新建一《serv-u》ftp服务器,在asp中修改指定帐户的密码,写了一asp组件来修改《serv—u》 ftp密码。
启动《vb6.0》,选择新建activex dll,更改工程属性中的工程名称为“ftpcommand”,将class名改为xjnftp,源程序如下:
private const scuseragent = "vb wininet"
private const internet_open_type_preconfig = 0
private const internet_open_type_direct = 1
private const internet_open_type_proxy = 3
private const internet_invalid_port_number = 0
private const ftp_transfer_type_binary = &h2
private const ftp_transfer_type_ascii = &h1
private const internet_flag_passive = &h8000000
private const internet_service_ftp = 1
private const internet_service_gopher = 2
private const internet_service_http = 3
private declare function internetopen lib "wininet.dll" alias "internetopena" _
(byval sagent as string, byval laccesstype as long, byval sproxyname as string, _
byval sproxybypass as string, byval lflags as long) as long
private declare function ftpcommand lib "wininet.dll" alias "ftpcommanda" _
(byval hconnect as long, byval fexpectresponse as boolean, byval dwflags as long, _
byval lpszcommand as string, byval lcontext as long, phftpcommand as long) as boolean
private declare function internetconnect lib "wininet.dll" alias "internetconnecta" _
(byval hinternetsession as long, byval sservername as string, byval nserverport as integer, _
byval susername as string, byval spassword as string, byval lservice as long, _
byval lflags as long, byval lcontext as long) as long
private hopen as long
private hconnection as long
private declare function internetclosehandle lib "wininet.dll" _
(byval hinet as long) as integer
private newpassword as string
private oldpassword as string
private username as string
private urlstr as string
‘修改ftp密码主程序
public function getstr() as string
hopen = 0
hconnection = 0
dim nflag as long
dim strcmd as string
nflag = internet_flag_passive
‘建立ftp修改密码命令字符串
strcmd = "site pswd " & oldpassword & space(1) & newpassword
‘建立internet连接
hopen = internetopen(scuseragent, internet_open_type_direct, vbnullstring, vbnullstring, 0)
if hopen = 0 then getstr = "不能打开连接。…"
if hopen <> 0 then
‘与ftp服务器建立连接
hconnection = internetconnect(hopen, urlstr, nternet_invalid_port_number, _
username, oldpassword, internet_service_ftp, nflag, 0)
if hconnection <> 0 then
bret = ftpcommand(hconnection, false, ftp_transfer_type_ascii, strcmd, 0, hfile)
if bret then
getstr = "密码修改成功!…"
else
getstr = "密码修改失败!…"
end if
else
getstr = "无法登录至ftp服务器,请检查帐户名或密码是否正确。"
end if
end if
‘断开internet连接
if hconnection <> 0 then internetclosehandle (hconnection)
‘断开ftp服务器连接
if hopen <> 0 then internetclosehandle (hopen)
end function
‘传入ftp服务器的url
public property let url(url1 as string)
urlstr = url1
end property
‘传入ftp原有密码
public property let oldpsd(psd as string)
oldpassword = psd
end property
‘传入ftp新密码
public property let newpsd(psd1 as string)
newpassword = psd1
end property
‘传入ftp帐户名
public property let user(psd2 as string)
username = psd2
end property
编译成ftpcommand.dll,在asp服务器端注册该组件,(vb6.0在asp服务器中自动注册),在asp中调用该组件,源程序如下:
<%
‘接受传入的帐户名
user=trim(request.form("id"))
‘接受传入的原密码
psw=trim(request.form("password"))
‘接受传入的新密码
pswx=trim(request.form("passwordx"))
‘创建ftp组件应用实例
dim obj
set obj = server.createobject("ftpcommand.xjnftp")
‘给ftp组件传送帐户名
obj.user=user
‘给ftp组件传送原密码
obj.oldpsd=psw
‘给ftp组件传送新密码
obj.newpsd=pswx
‘给ftp组件传送ftp服务器域名地址(url)
obj.url="ftp://ftp.luckybbs.com"
rr=obj.getstr()
response.write("<meta http-equiv=refresh content=3;url=/main.asp>")
response.write("<p><center><font color=#ff0000>"+rr+"!")
response.write("<center><font color=#ff0000>系统3秒钟后自动返回!!!</font></center>")
response.write("<br><center><a href=main.asp>返回</a></center>")
set obj=nothing
response.end
%>
本实例在windows 2000 server ,iis 5.0 ,serv-u4.0 ,vb6.0中通过。
zt:http://www.luckybbs.com
