.netrc and a here document to automate and script FTP

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

.netrc
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.
testf.bash
dtstr=$(date +%Y_%m_%d); export dtstr
cd /u01/app/oracle/fast_recovery_area/PROD/backupset/$dtstr
echo “date is: “$dtstr
ftp -v rh2 <<EOFMark
ls
mkdir $dtstr
cd $dtstr
prompt
mput *
quit
EOFMark

Leave a Comment

Scroll to Top