使用Excel VB FtpCommand来列出远程目录

我需要使用wininet.dll FTP命令function发送一些FTP命令。 当我使用QUIT命令时它正在工作。 但是当我尝试使用例如LSDIR我得到的响应0。

 Private Declare Function FtpCommand Lib "wininet.dll" Alias "FtpCommandA" (ByVal hConnect As Long, ByVal fExpectResponse As Long, ByVal dwFlags As Long, ByVal lpszCommand As String, ByVal dwContext As Long, phFtpCommand As Long) As Long Private Function test() Dim Success As Long Dim iRet As Integer Dim lngInet As Long Dim lngInetConn As Long Dim sCommand As String Dim test44 As Long sCommand = "DIR" Dim test5 As Long Dim lError As Long Dim strBuffer As String Dim lBufferSize As Long Dim retVal As Long lngInet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0) 'Open connection with fpt If lngInet = 0 Then iRet = MsgBox("bad") Else lngInetConn = InternetConnect(lngInet, Server.Value, 0, _ User.Value, Pass.Value, 1, 0, 0) 'Connect to server If lngInetConn > 0 Then Login = True blnRC = FtpCommand(lngInetConn, True, FTP_TRANSFER_TYPE_ASCII, sCommand, test44, test5) retVal = InternetGetLastResponseInfo(lError, strBuffer, lBufferSize) Else Login = False LoginError End If End If InternetCloseHandle (lngInet) 'Close Ftp I thnik is not necessary InternetCloseHandle (lngInetConn) 'Close Connection I thnik is not necessary End Function 

  1. FTP中没有DIRLS命令。 有LIST命令(或MLSDNLST )。
  2. 无论如何您都无法使用FtpCommand函数检索目录列表。 它只适用于一个简单的命令。 列表(或文件传输)需要与FtpCommand函数不提供的FTP客户端进行合作。

    改为使用FtpFindFirstFileInternetFindNextFile