通过VBA连接到FTP服务器,* .XLSB本地文件的“Put”功能

时间:2014-06-21 09:41:22

标签: excel-vba vba excel

我已经尝试了几种不同的东西,我在这里发现没有什么对我有用,如下所示:

Option Explicit
Const FTP_ADDRESS = "ftp.yourdestination.com"
Const FTP_USERID = "anon"
Const FTP_PASSWORD = "anon"

Sub Macro1()
    If Not SendFtpFile_F() Then
        MsgBox "Could not ftp file"
    Else
        MsgBox "Sent"
    End If
End Sub
Function SendFtpFile_F() As Boolean
  Dim rc As Integer
  Dim iFreeFile As Integer
  Dim sFTPUserID As String
  Dim sFTPPassWord As String
  Dim sWorkingDirectory As String
  Dim sFileToSend As String

  Const FTP_BATCH_FILE_NAME = "myFtpFile.ftp"
  Const INCREASED_BUFFER_SIZE = 20480

  SendFtpFile_F = False

  sWorkingDirectory = "C:\YourWorkingDirectory\"
  sFileToSend = "NameOfFile.txt"


  On Error GoTo FtpNECAFile_EH

   'Kill ftp process file if it exists
    If Dir(sWorkingDirectory & FTP_BATCH_FILE_NAME) <> "" Then
      Kill sWorkingDirectory & FTP_BATCH_FILE_NAME
    End If

    'Create ftp process file
    iFreeFile = FreeFile
    Open sWorkingDirectory & FTP_BATCH_FILE_NAME For Output As #iFreeFile
      Print #iFreeFile, "open " & FTP_ADDRESS
      Print #iFreeFile, FTP_USERID
      Print #iFreeFile, FTP_PASSWORD
      Print #iFreeFile, "mput " & sWorkingDirectory & sFileToSend
      Print #iFreeFile, "quit"
    Close #iFreeFile

    'Shell command the ftp file to the server
    Shell "ftp -i -w:20480 -s:" & sWorkingDirectory & FTP_BATCH_FILE_NAME

  SendFtpFile_F = True

  GoTo FtpNECAFile_EX


FtpNECAFile_EH:
    MsgBox "Err", Err.Name

FtpNECAFile_EX:


  Exit Function

End Function

任何人都可以提供帮助。我需要连接到我的“ftp服务器”并上传相同的excel文件(Closeout.xlsb)并在其中写入VBA代码。没有什么对我有用。

文件位置= C:\ Goodman输入文件 文件名= Closeout.xlsb

正在连接=“ftp.MyServer.com”

需要帮助,

锁定

0 个答案:

没有答案