Need to upload a file (file.txt) to a server (ftp.server.com) from Excel VBA. (does not have to be necessarily FTP, just need to be able to put the file there and get it bac
If you cannot use the Windows ftp.exe
(particularly because it does not support the passive mode and TLS/SSL), you can use another command-line FTP client.
For example to upload a file using WinSCP scripting, use:
Call Shell( _
"C:\path\WinSCP.com /log=C:\path\excel.log /command " & _
"""open ftp://user:password@example.com/"" " & _
"""put C:\path\file.txt /path/"" " & _
"""exit""")
To ease reading, the above runs these WinSCP commands:
open ftp://user:password@example.com/
put C:\path\file.txt /path/
exit
You can put the commands to a script file and run the script with /script=
command-line parameter, similarly to the ftp -s:
, instead of the /command
.
See the guide to Converting Windows FTP script to WinSCP script.
You can even have WinSCP GUI generate the FTP upload script for you.
WinSCP defaults to the passive mode.
You can also use FTPS (TLS/SSL):
open ftpes://user:password@example.com/
Alternatively you can use WinSCP .NET assembly via COM from the VBA code.
(I'm the author of WinSCP)