2
我試圖找到一個簡單的方法來通過FTP檢查用戶狀態,wininet似乎是最好的選擇。 如何從命令獲得輸出?使用wininet.dll檢索FTP命令輸出
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet As Integer) As Integer
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer, ByVal lContext As Integer) As Integer
Public Declare Function ftpCommand Lib "wininet.dll" Alias "FtpCommandA" (ByVal hConnect As Integer, ByVal fExpectResponse As Boolean, ByVal dwFlags As Integer, ByVal lpszCommand As String, ByRef dwContext As Integer, ByRef phFtpCommand As Integer) As Boolean
Dim INet, INetConn As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
INet = InternetOpen("MyFTP", 1, vbNullString, vbNullString, 0)
INetConn = InternetConnect(INet, "192.168.1.6", 21, "user", "pwd", 1, 0, 0)
strCommand = "SITE SHOW SERVER 192.168.1.6.21"
Dim retv As Long
Dim Test = ftpCommand(INetConn, True, 2, strCommand, 0, retv)
Debug.Write(Test)
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
End Sub
我期待的輸出是:
Response: 200- Server IP = "192.168.1.6"
Response: 200- Port = "21"
Response: 200- Start time = "10/02/2010 02:46:57 PM"
Response: 200- Download = "0.000 KB"
Response: 200- Upload = "0.000 KB"
Response: 200- Online Users = "0"
Response: 200-======================================
Response: 200 Site command OK
感謝。