FTP a text file to a server using VBA in Excel

前端 未结 1 767
我在风中等你
我在风中等你 2021-01-07 07:39

I have an Excel worksheet where the user enters certain data, which I want to store in a text file and upload to a server using FTP. One site suggested adding a reference to

相关标签:
1条回答
  • 2021-01-07 07:58

    Here is a solution I found by doing some Google search -

    Public Sub FtpSend()
    
    Dim vPath As String
    Dim vFile As String
    Dim vFTPServ As String
    Dim fNum As Long
    
    vPath = ThisWorkbook.Path
    vFile = "YourFile.csv"
    vFTPServ = "********"
    
    'Mounting file command for ftp.exe
    fNum = FreeFile()
    Open vPath & "\FtpComm.txt" For Output As #fNum
    Print #1, "user ***** *****" ' your login and password"
    Print #1, "cd TargetDir"  'change to dir on server
    Print #1, "bin" ' bin or ascii file type to send
    Print #1, "put " & vPath & "\" & vFile & " " & vFile ' upload local filename to server file
    Print #1, "close" ' close connection
    Print #1, "quit" ' Quit ftp program
    Close
    
    Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbNormalNoFocus
    
    SetAttr vPath & "\FtpComm.txt", vbNormal
    Kill vPath & "\FtpComm.txt"
    
    End Sub
    

    Original source: http://www.access-programmers.co.uk/forums/showthread.php?t=184692

    0 讨论(0)
提交回复
热议问题