views:

95

answers:

5

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
A: 

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

http://www.ncftp.com/

Rob Jones
i dont think this will work for his ssl requirement, will it?
djangofan
What ssl requirement?
Rob Jones
+2  A: 

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
ghills
beat me to it :)
mcandre
Check out pre-shared keys for this approach. It's a great way to keep passwords off the command line.
Rob Jones
nice hint mr. rob jones. thanks for that idea.
djangofan
Yeah I should have clarified I was assuming the pre-shared keys were set up for this scenario. Put your public key in the authorized_keys for the host you are transferring to.
ghills
this looks cool and simple. though i am not worried about putting passwords in the script as i am copying the file from prod to dev server...i would however would be interested in knowing about the pre-shared keys approach...any info how to implement this... as i said i a noob in unixthanks everyone for your prompt responses
Well generally you could do an ssh-keygen, then take your public key and place it in the authorized_keys file in the .ssh folder on the destination. See:http://sial.org/howto/openssh/publickey-auth/
ghills
+1  A: 

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
Mark L
A: 

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.

Matt Nizol
A: 

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.

djangofan