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 –