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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp 'hop' - 'get' then 'put' using 2 different servers

Status
Not open for further replies.
Feb 12, 2002
80
NO
Hi,

Due to networking issues, I am having to do an ftp 'hop' to move data from one location to another, via an intermediary.

i.e. location A contains original data, and I need to move it to location C:

ftp data from loc.A to loc.B, then ftp from loc.B to loc. C

I can do all work from location B - so 'get' the data from loc.A first, then 'put' the data to loc. C.

I am trying to work out a way to do this in a smart way. At the moment, I set off one ftp, leave it running over night (I'm moving several GB's at a time), then the next day, set off the second ftp. I use mget and mput, with prompt turned off.

Is it possible to script this somehow? someone suggested cron jobs, but I have ZERO experience of this.

I was thinking of some sort of script that would do the ftp for me, so I can have:
Code:
' Do ftp get part
cd /dir/dir
ftp locationA
[p/word here]
cd /dir/dir
prompt
hash
bin
mget *
close

' Do ftp put part
ftp locationC
[p/word here]
cd /dir/dir
mput *
close

But I have no idea how to force ftp commands out from a script, and how to do any error checking.

Any tips, ideas or previsoue useful posts appreciated.

Thanks,
littleIdiot
 
Ah ha - I found a way to get it to work, after finding the following page:

Code:
#!/bin/sh
GET_HOST='host_name'
GET_USER='username'
GET_PASSWD='password'
GET_DIR='/source/location'

PUT_HOST='xxx.xxx.xx.x'
PUT_USER='username'
PUT_PASSWD='password'
PUT_DIR='/target/location'


ftp -n $GET_HOST > ./ftpget.worked 2> ./ftpget.failed <<END_GET
quote USER $GET_USER
quote PASS $GET_PASSWD
cd $GET_DIR
dir
binary
prompt
mget *
quit
END_GET

ftp -n $PUT_HOST > ./ftpput.worked 2> ./ftpput.failed <<END_PUT
quote USER $PUT_USER
quote PASS $PUT_PASSWD
mkdir $PUT_DIR
cd $PUT_DIR
dir
binary
prompt
mput *
dir
quit
END_PUT


So - job done.

Asside from securty issues (password hard coded in script), can anyone see a problem with this?

Can anyone suggest a different way to get the password into my scipt ... I guess a prompt at the start of the script would be good - and store the values till the script exits.


littleIdiot
 
There are two options
[ol]
[li]use a .netrc file. This will have the password in clear text but you can control the permissions, indeed the permissions need to be pretty tight for it to work.[/li]
[li]use ssh with public private key pairs. This has the advantage that the password (and the data) is not transmitted across the network in clear text, plus the no password login. Most flavours of Unix/Linux have ssh available. My organisation (a bank) insists that it is used.[/li]
[/ol]

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top