user141511
user141511

Reputation: 349

ftp file from server1 to server2 in unix

i am a shell scripting noob.

i currently have a cronjob that runs every 15mts and check to see if a file exists.

If it exists, it takes the file and processes and then deletes it

Now, instead of deleting it, i want to make a copy and ftp it to Server2

below is the delete script. i want to modify it so that it makes a copy of the file and then ftps' it to the server2

rm -f /apps/pmserver/data/inbound/WPER594_COMPANY.CSV.proc

Upvotes: 1

Views: 562

Answers (5)

djangofan
djangofan

Reputation: 29669

i would say that command line putty (or PSFTP) would be the way to go. this is because it opens a tunnel through the SSH port 22 and uses regular FTP protocol controls. it would be the easiest. the hard part about it is that you have to compile the source code to get the PSFTP binary, but once you do your in business.

http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html

Its an alternative to SCP, but actually SCP is probably easier since linux systems are usually pre-installed with it.

Upvotes: 0

Matthew Nizol
Matthew Nizol

Reputation: 2659

You can execute FTP through a script in the following manner:

ftp -n $serverName <<!
verbose
ascii
quote user $username
quote pass $password
cd $targetdir
put $filename
quit
!

The above assumes you've set the variables beginning with $ earlier in your script. The content between the exclamation points will need to change based upon exactly what you want to do -- is it an ascii transfer or a binary transfer, etc -- but hopefully you get the idea.

Upvotes: 0

Mark L
Mark L

Reputation: 13425

I would use rsync:

THETIME=`date "+%Y-%m-%d_%H-%M-%S"`
rsync -avz -e ssh remoteuser@remotehost:/remote/dir/WPER594_COMPANY.$THETIME.CSV.proc /apps/pmserver/data/inbound/WPER594_COMPANY.CSV.proc
rm -f /apps/pmserver/data/inbound/WPER594_COMPANY.CSV.proc

Upvotes: 1

Gavin H
Gavin H

Reputation: 10482

well if you aren't dead set on ftp, I would actually just use scp.

scp /apps/pmserver/data/inbound/WPER594_COMPANY.CSV.proc username@server:/path/to/dest

Upvotes: 2

Rob Jones
Rob Jones

Reputation: 4985

Check out ncftpput and the ncftp package. It's great for scriptable ftp.

http://www.ncftp.com/

Upvotes: 0

Related Questions