Using FTP in WSH
(Page 1 of 4 )
From time to time you may find yourself creating scripts that require FTP support. Maybe you’re creating a script that will auto-update your web site contents or perhaps your script needs to check an ftp site for program updates or additional components to install.
In any of these cases, it can be helpful to add FTP functionality to your scripts. Unfortunately, the Windows Script Host does not provide any method for doing so natively. You can, however, create a usable workaround using the command-line FTP utility included with Windows.
Before we begin, let’s examine the command-line FTP utility. It’s called FTP.exe and is located in the System32 directory. Let’s take a peek at its command-line syntax.
FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [host]
where:
-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A Login as anonymous.
-w:buffersize Overrides the default transfer buffer size of 4096.
host Specifies the host name or IP address of the remote host to connect to.
While you can use any of these switches to suit your needs, we’ll be concentrating on the –s switch. It allows us to specify an input file that contains a set of commands to be executed during the ftp session. This allows us to create an unattended ftp session.
In other words, we can execute the ftp command without having to input anything interactively on the command line. This is perfect for our scripting needs. All we need to do is determine the necessary commands and create the text file before we execute the FTP command.
Next: Creating the Unattended FTP script >>
More Windows Scripting Articles
More By Nilpo