.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


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
cd /u01/app/oracle/fast_recovery_area/PROD/backupset/$dtstr
echo “date is: “$dtstr
ftp -v rh2 <<EOFMark
mkdir $dtstr
cd $dtstr
mput *

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s