Friday, January 27, 2006

Scripted FTP in Unix

A scripted FTP session in Unix can be made with this (Korn) shell script:

#!/usr/bin/ksh

if [ "$1" -eq "" ] ; then
echo specify a file to send.
exit 1
fi

echo sending file $1 to /home/userid/ff on hostname.domain.
echo "open hostname.domain
verbose
cd ff
bin
put $1
quit" | ftp


This needs a file .netrc in your home directory where the userid and password for the session are stored. This file must have its access permissions set to 600.
The format of this file is:

host hostname.domain login userid password passwd

where "userid" and "passwd" are substituted with the userid to use on the host, and the password for that user.

No comments: