Reader to Reader - 20 Mar 2000

This month, one scripting solution is provided: Script Automatically Downloads FTP File

Readers

March 20, 2000

2 Min Read
ITPro Today logo in a gray background | ITPro Today


[Editor's Note: Email your scripting solutions (400 words or less) to Reader to Reader at [email protected]. Please include your script and phone number. We edit submissions for style, grammar, and length. If we print your contribution, you receive $100.]

The short Windows NT shell script in Listing 1 packs a lot of power. I use it nightly in a scheduled FTP download of a file named FH, where YYMMDD is yesterday's date in the specified format.

The code in the script's first section obtains the current date and transforms it into a string that follows the format YYMMDD. To perform this action, the script uses the Date command with the /t switch to return a date such as Tue 02/22/2000. Next, the script uses the For command with the slash and space delimiters to parse that string into four components (e.g., Tue, 02, 22, 2000). The script ignores the first component (e.g., Tue), rearranges the rest into the YYYYMMDD format (e.g., 20000222), and assigns the result to the %date% environment variable. The Set /a line subtracts 1 from the value that the %date% variable holds (e.g., 20000221). The code %date:~2,6% returns characters 3 through 8 of %date% (e.g., 000221).

The code in the script's second section writes a list of FTP responses to the text file ftpcmd.txt. The script starts by writing the userid and password, then writes the output of several FTP commands, including the Get command. This command copies the remote file FH to C:ftpcmd.txt.

Finally, the script launches the FTP session. The script redirects any further input to ftpcmd.txt.

The FTP download script in Listing 1 works under Windows 2000 (Win2K) and NT. To use the script, you must enable the command extensions. You also need to replace the generic terms in the script with your specific names (e.g., myID, myServer).

—Jon Hill
[email protected]

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like