So, I am after an FTP upload code that works. I have tried a couple of versions, but they do not seem to work.
One of the codes, it does upload the file, but for some reason it sends it blank. But the local file has data, and when I use FileZilla, it sends the same file okay.
Code:
Function cmdFTPUpload()
'=========================================================================
'FTP from Microsoft Access
'by Matthew V Carmichael
'Craetes FTP Batch File, FTP command file (txt)
'Default directory location of files to upload/download is
'the same location as the mdb file that contains this module.
'========================================================================='
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
'Create the file to transfer
'DoCmd.TransferText acExportDelim, , "QUERY TO CREATE FILE", "FILE NAME.csv"
'Path and Name of file to FTP
strPath = "C:\"
strFileName = "FILENAME.csv" 'Name of file to upload
'FTP Server Settings
ftpServer = "FTP SERVER"
strUserName = "USER NAME"
strPassword = "PASSWORD"
'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 " & strPath & strFileName
Print #pFile, "quit"
Close pFile
'Create batch file to execute FTP
pFile = FreeFile
Open strPath & "FTP_Run.bat" For Output As pFile
Print #pFile, "CD """ & strPath & """"
Print #pFile, "ftp -n -s:" & "FTP_cmd.txt " & ftpServer
Print #pFile, "Pause"
Close pFile
'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
The above code always says failed, but it does upload a blank file...
PS: In the cmd screen, it says Error 426 Transfer Failed, but it does send a .csv file with the same name, but it has no data in it (0 bytes)
~Matt