使用Excel VB FtpCommand列出远程目录

使用Excel VB FtpCommand列出远程目录,excel,ftp,vba,Excel,Ftp,Vba,我需要使用wininet.dll中的FTP命令函数来发送一些FTP命令。当我使用QUIT命令时,它正在工作。但当我尝试使用例如LS或DIR时,我得到的响应为0 Private Declare Function FtpCommand Lib "wininet.dll" Alias "FtpCommandA" (ByVal hConnect As Long, ByVal fExpectResponse As Long, ByVal dwFlags As Long, ByVal lpszCommand

我需要使用
wininet.dll
中的FTP命令函数来发送一些FTP命令。当我使用
QUIT
命令时,它正在工作。但当我尝试使用例如
LS
DIR
时,我得到的响应为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
  • FTP中没有
    DIR
    LS
    命令。有
    LIST
    命令(或
    MLSD
    NLST
  • 无论如何,不要使用
    FtpCommand
    功能

    使用和代替


  • 有没有办法直接向ftp发送ftp命令,而不是先创建txt纸条?我需要这个,因为在txt文件,你可以看到一个密码,即使我创建的功能,将删除此密码仍然是危险的,当有人崩溃的程序和删除密码的功能将不会运行我不明白你的问题。您没有使用任何脚本文件。您将内存中的密码传递给
    InternetConnect
    。我有另一个版本的应用程序,它使用脚本将一些文件发送到服务器,我在那里存储了一个密码,但忘记了它。我直接将命令发送到cmd,它正在工作。谢谢你的帮助