Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.netrc - multiple ftp jobs to the same machine

Status
Not open for further replies.

gfunk123

IS-IT--Management
May 22, 2001
143
0
0
GB
I have an ftp user, which has been setup to run ftp jobs to a specific machine (different jobs). for the first job i created .netrc in the ftp users home directory and added the appropriate commands

machine FTPBOX01 login user1 password xxx
macdef init
etc
etc
get file
bye

I use the command 'ftp FTPBOX01' in my shell script to call the entry for that machine in my .netrc file

However, I need this user to be able to run different jobs but on the same machine , for example my .netrc file would look something like this:

machine FTPBOX01 login user1 password xxx
macdef init
etc
etc
get file
bye

machine FTPBOX01 login user2 password xxx
macdef init
etc
etc
get another file
bye


however, because i am using the 'ftp FTPBOX01' command it cant dtermine which job to run it just gets the first matching entry in .netrc (ie the top one)

How can specify from within my shell script which job i want to run, somebody has suggested that i create a different ftp user with its own .netrc file, but this is not an option as there will possibly be hundreds of jobs to the same machine

Any help on this would be greatly appreciated

Thanks and regards
Gary
hcclnoodles@hotmail.com
 
You may want to try to create a script file for each and
run the jobs seperately in cron. If you have both in the
same file it would run both at one time. The .netrc is
primarily for direct connection to the host you are want
to ftp to. Try this it worked for me...
 
.netrc is only to allow automatic connection to the host. If you create a separate file containing your ftp commands, then you can run each script separately by saying ftp machine < scriptname

Greg.
 
You might want to look into ssh/scp; that way, there are no passwords anywhere in cleartext. You just have to keep your private key read-only by the user (400). :)
 
Hi
The easiest way to do multiple ftp jobs like this to the
same box is to just add an extra alias in the /etc/hosts
file. For example, you have FTPBOX01, so add the aliases
FTPALIAS1 and FTPALIAS2 for example, then in the .netrc
you can refer to each one separately and have them do
different jobs.
HTH

John John Philcox
Mobile Ventures Limited UK
 
I do this by creating the .netrc file for each transfer :

function ftp_transfer
{
tput cup 7 0
echo &quot;TRANSFERRING $LOCAL_FILE &quot;
cat > $HOME/.netrc << !!
machine $REMOTE_BOX
login $LOGIN
password $PASSWORD
macdef init
put $LOCAL_FILE $REMOTE_FILE
bye
!!

chmod 600 $HOME/.netrc
ftp $REMOTE_BOX
rm $HOME/.netrc
}

so you can transfer various files to various machines by changing the variables.
hth
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top