新建一《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中透過。
|
|