Using FTP in WSH - Creating the Unattended FTP script
(Page 2 of 4 )
In order to understand better what needs to be in the unattended ftp script, let’s take a look at an example ftp session. Here I’ve simply connected to my ftp site and downloaded a file. For security purposes, all sensitive information has been changed in the output below.
C:>ftp ftp.myserver.com
Connected to ftp.myserver.com.
220---------- Welcome to Pure-FTPd [TLS] ----------
220-You are user number 4 of 50 allowed.
220-Local time is now 13:14. Server port: 21.
220-IPv6 connections are also welcome on this server.
220-You will be disconnected after 15 minutes of inactivity.
User (ftp.myserver.com:(none)): USERNAME
331 User USERNAME OK. Password required
Password:
230-Your bandwidth usage is restricted
230-User USERNAME has group access to: USERNAME
230 OK. Current restricted directory is /
ftp> cd /public_html/pub/examples
250 OK. Current directory is /public_html/pub/examples
ftp> get word.vbs
200 PORT command successful
150 Connecting to port 61110
226-File successfully transferred
226 0.006 seconds (measured here), 146.10 Kbytes per second
ftp: 858 bytes received in 0.00Seconds 858000.00Kbytes/sec.
ftp> close
221-Goodbye. You uploaded 0 and downloaded 1 kbytes.
221 Logout.
ftp> bye
I’ve used a bold font to indicate the information that I typed manually at the interactive prompt. Essentially, these entries become the commands that we’ll use in the unattended ftp script. You could add any other ftp commands that you like to your session. Each line will be executed in turn whenever a prompt appears that required user input.
Here is what the unattended script for my ftp session would look like.
USER username
password
cd /public_html/pub/examples
get word.vbs
Notice that you can safely leave out the close and bye commands. The ftp session will be terminated as soon as it reaches the end of the script file.
There are a couple of things to keep in mind. First, know your ftp server. Some servers have different settings and may require other input. Second, avoid unexpected errors. Using commands like “binary” to specify a binary transfer mode for images or executables can prevent unwanted errors even though most servers will auto-sense the correct settings.
It’s also important to suppress unwanted confirmations. If you are sending or receiving multiple files at once (using mput or mget, respectively) you will be prompted to continue before each transfer. You can suppress this by using the “prompt n” command prior to using mput or mget or you can use the –i switch in your ftp command line.
In any case, test and retest your script to make sure it functions properly. If your script is going to be used for distribution, take care in making it fully compatible with all ftp servers on which it may be used.
Next: Putting the WSH script together >>
More Windows Scripting Articles
More By Nilpo