FTP batch files

Last Updated on November 21, 2016 by Dave Farquhar

I found this question on the Sys Admin magazine forum:
Can I create a batch file (or something else) to allow me to execute my file transfer from a Tru64 UNIX to a NT without having to type each command? This is what I’m doing now to transfer a recompiled data base from UNIX to NT: At the NT machine:

C:> cd\sandgis
sandgis> erase *.*
are you sure? Y
sandgis> ftp 000.00.000.0
name: *******
passwd: ********
ftp> cd /data/sandgis
ftp> prompt off
ftp> bin
ftp> mget *.*
ftp> cd /apps/sandcauv
ftp> mget par*.*
ftp> quit
sandgis> cd info
sandgis\info> erase *.*
are you sure? Y
sandgis\info> ftp 000.00.000.0
name: ****
passwd: *****
ftp> cd /data/sandgis/info
ftp> bin
ftp> prompt off
ftp> mget *.*
ftp >quit
(this is half of it)

Well, you get the idea… I can get a batch file to work until it goes into FTP, then it stops. Since I’ve got to do this on five NT machines twice a week and the total files size is near half a gig., this is very time consuming.

And here’s the response I submitted:

Put your pre-FTP commands in a batch file, as it sounds like you already have, then add the -s:[textfile] parameter to your FTP statements containing FTP commands, e.g. ftp -s:ftp1.txt 000.00.000.0.

The contents of ftp1.txt, based on your example:
name
password
prompt off
bin
mget *.*
cd /apps/sandcauv
mget par*.*
quit

Anything you put in a file specified by the -s parameter gets fed to your FTP client.

So, you’ll need a batch file, plus a text file for each FTP session, which could turn into a real mess of files, but it’s a whole lot better than typing all that garbage twice a week.

If you found this post informative or helpful, please share it!