Looks like I also found a nice quick way to download files off my webserver using a ftp script. It’s so simple that I don’t know why I didn’t even think of it before! Before I had this script, I had to manually download my sysadmin-tools from my website onto the remote servers I was doing maintenance on that particular day. That took about 3-5 minutes each time I had to download the tools I had in a zip file on my webserver, which as you can imagine get really repetitive and annoying after a while. So after about the 50th time downloading the sysadmin-tools, I decided to automate it!
This is how I approached creating the script:
1. It has to work out of the box with Windows (I administer and maintain Windows Server 2003 boxes)
2. It had to connect to my webserver using my username and password
3. It had to change directories on the server to the download directory
4. K.I.S.S (keep it simple stupid!)
Decisions:
After reviewing the script requirements, I decided to write a simple batch script using the built in FTP command in windows. I didn’t know windows had a built in FTP command to tell you the truth until I starting writing the script.
Unattended FTP Script:
Below are the contents of the batch file:
@echo off
ftp -s:ftpscript.txt
Below are the contents of the ftpscript.txt file:
open
yourserver.com
username
password
cd “/public_html/yourdownloadfolder”
binary
get “sysadmin-tools.zip” “C:\Users\username\Desktop\sysadmin-tools.zip”
quit
Explanation:
It’s pretty straightforward, the batch file using the ftp command to start the built-in ftp program in windows. After that the batch script calls the “ftpscript.txt” file to supply the ftp command to execute. In the ftpscript.txt file it basically says to connect to a server, enters a username and password, then changes directories to the directory that contains the file you wish to download, switches the FTP mode to binary so it will download the .zip file correctly, downloads the file to somewhere on my Desktop, and finally quits FTP.
FTP Modes:
Make sure you are downloading in the right FTP mode!! I was getting corrupted files at first when I was making the script because I was downloading the .zip file in the wrong mode. Once I changed to binary it downloaded successfully without any corruption issues.
Text files (html, php, css, java) — use text mode
Multimedia files (images, audio, video) — use binary mode
Programs (.exe, .class, .jar, .swf) — use binary mode
References:
http://www.robvanderwoude.com/ftp.php
http://www.bluehostforum.com/showthread.php?t=9311
