Using a .netrc file combined with a “Here Document” for ftp scripting can simplify ftp scripting by automating the login and setting up macros – that can be run from a scripted ftp session
Here is an example .netrc file from something I did recently. Note do a “chmod 600 .netrc” after you have created the file to give it the correct file permissions to be used.
- the first line specifies a machine name that can be automatically logged into
machine myhostname login remoteusername password remotepassword
Now here is the “Here Document” contained in the bash script testf.bash that does most of the work.
dtstr=$(date +%Y_%m_%d); export dtstr
echo “date is: “$dtstr
ftp -v rh2 <<EOFMark