Operating System - Linux
1827704 Members
3116 Online
109967 Solutions
New Discussion

Re: sftp - a better way to script?

 
TwoProc
Honored Contributor

sftp - a better way to script?

I've noticed that scripting sftp using "expect" is pretty unreliable if timing isn't right.

Has anyone come up with a better way to script sftp transfers from HPUX? A better sftp tool running on HPUX perhaps?

Does anyone have example perl code I use as a base to get started?

Other suggestions?

Thanks very much in advance,

John
We are the people our parents warned us about --Jimmy Buffett
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: sftp - a better way to script?

Hi John:

Perl has a core module 'Net::FTP'.

http://perldoc.perl.org/Net/FTP.html

Regards!

...JRF...
Heironimus
Honored Contributor

Re: sftp - a better way to script?

When I script secure transfers I usually use scp rather than sftp. scp doesn't try to be interactive, but it also doesn't have all the same functionality as sftp (renaming files and such). For things like that I usually run remote commands through ssh instead.

Another option would be lftp, which can open sftp sessions and is supposed to be reasonably script-friendly. I haven't used it on HP-UX so I don't know if it has any issues.

Net::SFTP would be the appropriate perl module, not Net::FTP. I've never used it, so I can't comment on how well it works.
James R. Ferguson
Acclaimed Contributor

Re: sftp - a better way to script?

Hi (again) John:

Sorry, I read too fast! CPAN has an 'sftp' module, 'Net::SFTP':

http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm

Regards!

...JRF...
Geoff Wild
Honored Contributor

Re: sftp - a better way to script?

Use keys!

Then no need to worry about passwords....

Example shell script:

#!/bin/sh
#### script to transfer .csv files over to Comapny INTL ####
### contact John Doe for Help ###
## script Written by Me ##
set -xv
cd /export/APPL/xxx/outbound
cp -r * ../backup
for i in `ls -1 pctcp*.csv` ; do echo $i ; fname=`echo $i | awk -F. '{print $1}'` ; echo $fname ; mv $i $fname.txt ; done
sftp -b /export/APPL/xxx/batchscript auserid@sftp.somewhers.ca
pwd
mv * /export/APPL/xxx/archive


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
TwoProc
Honored Contributor

Re: sftp - a better way to script?

JRF, thanks I knew that CPAN has a module, I was hoping to find someone already using it, and had an example perl script I could modify to make it work - my Perl skills are lacking, to say the least. I've "made" things work, but I'm pretty awfull with it, even on a good day. I do appreciate the advice, however, all help from the great people in this forum is always appreciated.

Geoff, I don't know why, but I can't get the keys to work on the "other guy's" machine. I don't know if he can't set something up right, etc. I have no problem using it here across many different platforms, but I'm not the admin on their box, and I can't get them to want to fix their problem badly enough (I guess).

Thanks all, any more ideas greatly appreciated.

Anyone familiar with using a product called "sftpplus" by ProAtria?

We are the people our parents warned us about --Jimmy Buffett