Operating System - HP-UX
1825982 Members
3135 Online
109690 Solutions
New Discussion

Script question - how to automate an sftp process

 
SOLVED
Go to solution
John Henrikson
Regular Advisor

Script question - how to automate an sftp process

Hi folks -
I need to script a process to transfer a directory of files created daily to a remote server. The directory will be named by the date created - for example yesterday's is 20071212.
I need to transfer the directory and all its files.. I sure appreciate any suggestions! Thanks so much ..

John Henrikson
Univ. of Missouri
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: Script question - how to automate an sftp process

Hi John:

Perl enables you to perform FTP and SFTP and makes the error handling simple.

The Net::FTP module comes with the core Perl distribution and Net::SFTP is available from CPAN for installation.

Regards!

...JRF...
erics_1
Honored Contributor

Re: Script question - how to automate an sftp process

John,

Why not script rsync to do this for you via ssh? As long as root keys are in place, you could rsync the directory over to the destination via cron daily. It also avoids hard-coding passwords in a script.

Regards,
Eric
Dave Hutton
Honored Contributor

Re: Script question - how to automate an sftp process

Will scp work verses sftp? It would make scripting it a bit easier.

John Henrikson
Regular Advisor

Re: Script question - how to automate an sftp process

I think scp would work.. and the perl idea is probably a good one, although I'm no expert in it. How would a script look that would increment the directory to be sent each day? that's what has me scratching my head I guess..
thanks again..
JH
Dave Hutton
Honored Contributor
Solution

Re: Script question - how to automate an sftp process

Easiest is search for caljd.sh its all through out this site.

Something like
#!/usr/bin/sh
DAYPRIOR=$(/usr/local/bin/caljd.sh -y -s $(/usr/local/bin/caljd.sh -p 1 ))

ssh mkdir remotehost mkdir /filesystem/${DAYPRIOR}
scp -pr /filesystem/directory remotehost:/filesystem/$DAYPRIOR}

Very basic example. No error checking at all. But you should get an idea of what I'm getting at.
John Henrikson
Regular Advisor

Re: Script question - how to automate an sftp process

thanks for the script info! very useful..