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 back, and I've got a server on GoDaddy shared hosting)
What I tried was to run this script:
ftp -s:script.txt
script.txt:
open ftp.server.com
USER
PASS
lcd c:\
put file.txt
disconnect
bye
The error I get is:
425 Could not open data connection to port 53637: Connection timed out
Google tells me I need to go to passive mode, but the command-line ftp.exe
client doesn't allow that.
Anyone know of any free (open source) command-line FTP client that allows passive mode?
Do I have an easier alternative to FTP?
Is there a better way to upload a file via VBA (without the command-line workaround)?
I'm thinking about using DROPBOX (but I really don't want to have to install this program on all the workstations that will need the program).
The above script is great I used the following commands to upload files as well as log the output to a file which is useful when debugging also it is a common misconception that windows ftp cannot do passive mode the command to go passive is "quote pasv" (I have added this to the script
http://winscp.net is free, scriptable, supports passive mode and is definitely EXCELLENT.
After lot of research I found a method to upload file to FTP location without any .ocx file internet control file. This worked for me....
Please change values as per your needs
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:
To ease reading, the above runs these WinSCP commands:
You can put the commands to a script file and run the script with
/script=
command-line parameter, similarly to theftp -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):
Alternatively you can use WinSCP .NET assembly via COM from the VBA code.
(I'm the author of WinSCP)
Diego, I've used the code below successfully for years. The code gets files from the host, but I'm sure it can be modified to put files there instead.