I really love DOS commands. They are so powerful and yet simple (most of the time). Few days back I was required to create a script to download files from FTP site to local folder, and this has to be done at scheduled time. I decided to use my all time favorite script language to do this job …. yes a batch file with dos commands, honestly it is not like that I am partial to batch file and dos commands (hmm, may be a little bit) but I personally find PowerShell a bit cryptic. And thus I try to avoid it’s use (plus our production servers don’t have PowerShell installed)
Ok, aside from my reasons for not using PowerShell, I was able to create a tiny script for my task. Script is very simple, it opens up a connection to ftp site. Provides user id and password. Selects FTP download directory (in this demo script it also selects file). And download it to local folder. And this is a simple TEXT file.
open ftp.microsoft.com anonymous firstname.lastname@example.org cd \softlib lcd D:\Temp\ get README.TXT prompt n quit
But to run a FTP script you will need to also create a batch file which initiates this ftp script on FTP command. So I created another batch file to execute this FTP script.
rem @echo off ftp -s:"D:\Temp\ftp_test.txt" <—name of txt file (above) pause
And you are all set. This script will download “README.TXT” file off the MSFT FTP server into D:\Temp folder. If you are curious you can browse MSFT FTP site, which is same as Microsoft.com.
That’s it for now.
It’s Just A Thought …