LKBEN10615: Howto automate FTP with vbscript and windows scripting host for free


Symptom

Difficulties automating FTP transfers

Cause

none

Solution

Some developers think they need a third-party tool or some complex source code to do FTP. There is an easier way to do FTP with scripting windows scripting host. The FTP executable from Windows has a command line option for running scripts.  You can schedule regular FTP scripts using Task Scheduler. (AT command)

You should make a text file for the script which can be used as parameter for the ftp command and and put your ftp command in it.

open your.ftp.site.comusername
password
prompt
cd tfptest
cd download
bin
mget testfile*
quit

The script above would FTP to your.ftp.site.com and do a logon with username and password. Then it changes directory and gets some testfiles. You can run this script in visual basic Script like:

Set objShell = CreateObject("WScript.Shell")

objShell.Run "cmd /c c:\winnt\system32\ftp.exe -s:filename" >> " & FTPLogfile, 1, True

Set objShell = Nothing

The FTPLogfile is optional and can be used to do some logging. We use this for automating ftp.

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.