1820475 Members
3314 Online
109624 Solutions
New Discussion юеВ

using sftp with perl

 
SOLVED
Go to solution
Brian Bartley
Frequent Advisor

using sftp with perl

I want to script sftp transfers, and we have a working version of sftp from our SSH installation.

Is there a Perl module that simply wraps the existing sftp on the system and allows scripting similar to Net::FTP, except with sftp?

I don't want the modules that have their own native sftp built-in such as Net::SFTP, that's major overkill for just sending a few files, and I've no luck installing Net::SFTP on my test Linux machine, it fails with many errors.

I want to use our existing sftp program, but I need a way to script the username/password exchange in order to automate the transfers. Thanks,

Brian
Brian Bartley
Campus Card Services
Indiana University
11 REPLIES 11
Court Campbell
Honored Contributor

Re: using sftp with perl

You could try Net::SFTP::Foreign.

http://search.cpan.org/~salva/Net-SFTP-Foreign-1.31/lib/Net/SFTP/Foreign.pm
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Brian Bartley
Frequent Advisor

Re: using sftp with perl

Thanks, for a minute that looked like a good solution, but Net::SFTP::Foreign apparently doesn't have any feature for passing a username and password. The Windows machine I'm transferring to probably does not support hostbased auth, so I need a way to send username/password strings.

I'm surprised this is so difficult. I have Net::Ftp now and it works great, but it's plain-text, not encrypted. Also I have command line sftp, again it works great, I can easily transfer a file via sftp to the desired machine. But to automate the sftp process is unbelievably difficult.

Any other suggestions are welcome. Thanks,

Brian
Brian Bartley
Campus Card Services
Indiana University
TwoProc
Honored Contributor

Re: using sftp with perl

There is a Net:SFTP package out there. But, I found it pretty tricky to build (much easier on Linux fwiw). It was so inconsistent to build between test servers, I decided not to fool with it. The biggest issues seemed to be around some of the Crypt:DES and similiar builds which relied on Math:Pari. This didn't build automatically at all, and took days and days of work (and failures) to get it loaded. Once I had it working I started a map of what and how to load and failed miserably, went to a whole 'nother box and began again, and got it working. Seemed so nasty of an install, with SO MANY bad dependencies, I decided to not even use it. I was worried about patching up , and once I became dependant on it, having it break again.
We are the people our parents warned us about --Jimmy Buffett
David Bellamy
Respected Contributor

Re: using sftp with perl

Brian if you don't already have it, bring down expect. Expect will allow you to use the native sftp and pass in a username and password.
Court Campbell
Honored Contributor

Re: using sftp with perl

I guess I could have read the bold printed statement on the page:

Net::SFTP::Foreign does not (and will never) allow to use passwords for authentication

Sorry.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Brian Bartley
Frequent Advisor

Re: using sftp with perl

TwoProc: You're not kidding, I tried installing Net::SFTP on a Linux machine and the results were horrid. It wanted module after module and I had no idea how to respond to the prompts. Needless to say I've eliminated Net::SFTP as a solution. I'm glad to hear someone else suffered the same problems and that it wasn't just me.

David: I don't have Expect, I wonder if a precompiled binary like this would work:
http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.43/
I don't have much faith in our compiler or my ability to compile, but it appears Expect only needs one other program, Tcl. Maybe I could get those two programs and try that route. I don't suppose HP has pre-compiled depots for Expect and Tcl? Thanks,

Brian
Brian Bartley
Campus Card Services
Indiana University
TwoProc
Honored Contributor

Re: using sftp with perl

Well, the regular Net:SFTP does do password handling fine (I got it working in my tests just fine). But the build is a monster and worrisome to be dependent on such a rickety and maddening set up (at least for us). I ended up using expect to get it done.
We are the people our parents warned us about --Jimmy Buffett
David Bellamy
Respected Contributor
Solution

Re: using sftp with perl

The binaries work fine that the one i'm using.
TwoProc
Honored Contributor

Re: using sftp with perl

Brian Google up the "HPUX Porting Archives" for a pre-built expect executable. The one for the US is at utah.edu or utah.cs.edu (forget which). You'll find it on Google easily enough. The pre-built binaries work fine to a point - I had a few bugs and had to recompile to get some minor features working. The source is available there too, and it's not a bad build at all (from what I remember).
We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: using sftp with perl

Instead of prior posting with "utah.cs.edu" that's more likely to be "cs.utah.edu" for the HPUX porting archive.
We are the people our parents warned us about --Jimmy Buffett
Brian Bartley
Frequent Advisor

Re: using sftp with perl

Thanks for all replies, this is a great forum. I'll try the Expect solution, and I'll also ask the folks with the Windows server to see if they can do something hostbased that doesn't require passing credentials.

Brian
Brian Bartley
Campus Card Services
Indiana University