0
我正在使用以下功能使用FTP將文件上載到服務器。使用Access VBA的FTP在沒有數據的服務器上創建文件
但文件大小爲零。該文件不包含數據。無法弄清楚我在實現該功能時犯了什麼錯誤。
Function FTP_Data()
'=========================================================================
'FTP from Microsoft Access
'by Matthew V Carmichael
'Creates FTP Batch File, FTP command file (txt)
'========================================================================='
On Error GoTo Err_Trap
Dim pFile As Long
Dim strPath As String
Dim strFileName As String
Dim ftpServer As String
Dim strUserName As String
Dim strPassword As String
'Path and Name of file to FTP
strPath = "C:\Temp\"
strFileName = "C:\Temp\AccessDocumentation.pptx" 'Name of file to upload
'FTP Server Settings
ftpServer = "ftp.mydomain.com"
strUserName = "[email protected]"
strPassword = "****"
SetAttr strPath & "FTP_cmd.txt", vbNormal
'Create text file containing FTP commands
pFile = FreeFile
Open strPath & "FTP_cmd.txt" For Output As pFile
Print #pFile, "user"
Print #pFile, strUserName
Print #pFile, strPassword
Print #pFile, "Put " & strFileName
'Use the Put command to upload, use the Get command to download.
'Print #pFile, "Get " & "Your File Name"
Print #pFile, "quit"
Close pFile
'Create batch file to execute FTP
pFile = FreeFile
Open strPath & "FTP_Run.bat" For Output As pFile
Print #pFile, "ftp -n -s:" & strPath & "FTP_cmd.txt " & ftpServer
Print #pFile, "Pause"
Close pFile
SetAttr strPath & "FTP_cmd.txt", vbHidden
'Execute FTP command
Shell strPath & "FTP_Run.bat", 1
Err_Trap_Exit:
Exit Function
Err_Trap:
MsgBox Err.Number & " - " & Err.Description
Resume Err_Trap_Exit
End Function
PS:新的VBA編程。
它會手動運行嗎?你確定它不應該讀取:'strUserName =「user」'? – Gustav
是的,第一步應該是創建一個工作的FTP_Run.bat + FTP_cmd.txt,第二步通過VBA創建這些(這應該是簡單的部分)。 – Andre
@Andre我試着手動運行它,發現同樣的問題。因此創造了另一個相同的問題 - http://stackoverflow.com/questions/35743072 –