Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

SFTP perl script

by Anonymous Monk
on Apr 28, 2008 at 13:20 UTC ( [id://683289]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am relatively new to perl and I am attempting to get a script working that uses SFTP. The script I am using is:

#!/usr/bin/perl -w use Net::SFTP; my $host = "10.10.10.10";<br> my %args = (<br> user => 'user',<br> password => 'pass',<br> debug => 'false'<br> ); my $sftp = Net::SFTP->new($host, %args);<br> print "connected!"; $sftp->get("/tmp/tmp/test2.txt", "/home/advserv/sean/test2.txt");
When I run this script, it only works intermittently, i.e. sometimes it works fine, but more often then not, I get the folllowing error:
# ./sftp2.pl<br> advlogs: Reading configuration data /home/advserv/.ssh/config<br> advlogs: Reading configuration data /etc/ssh_config<br> advlogs: Connecting to 10.10.10.10, port 22.<br> advlogs: Remote version string: SSH-2.0-OpenSSH_4.1 advlogs: Remote protocol version 2.0, remote software version OpenSSH_ +4.1<br> advlogs: Net::SSH::Perl Version 1.30, protocol version 2.0.<br> advlogs: No compat match: OpenSSH_4.1.<br> advlogs: Connection established.<br> advlogs: Sent key-exchange init (KEXINIT), wait response.<br> advlogs: Algorithms, c->s: 3des-cbc hmac-sha1 none<br> advlogs: Algorithms, s->c: 3des-cbc hmac-sha1 none<br> Segmentation Fault (core dumped)
I have the core file that is dumped if you require it.

I did try to upgrade the version of perl, and related libraries, and it doesnt seem to make a difference. I did come across something strange though (as an aside). Before I upgraded, the perl version was:

# perl -v This is perl, v5.6.1 built for sun4-solaris-64int (with 48 registered patches, see perl -V for more detail)
I then upgraded to:
# perl -v This is perl, v5.10.0 built for sun4-solaris
This didnt fix my SFT problem above, but another thing I saw was that the perl version is the latest when I run "perl -v" as user root (which is the user that installs the various perl libraries), but it is still the older version when I run "perl -v" as another user. This particular user is the user that owns and runs the sftp script above.

Any ideas what is happening? If you need any more info off me, just let me know.

Thanks.


Update:

Hi Guys,

Just to let you know your comments were very helpful. I am now using Net::SFTP::Foreign and it is working very well. I too had problems with libssh2, so I didnt persue the Net::SSH2 option.

I have alos got my PATH Environment Variables sorted out now, so all users using latest version of perl.

Thanks again for the help.

Replies are listed 'Best First'.
Re: SFTP perl script
by zentara (Archbishop) on Apr 28, 2008 at 14:07 UTC
Re: SFTP perl script
by salva (Canon) on Apr 28, 2008 at 16:18 UTC
    Try using Net::SFTP::Foreign instead.

    It is known to work reliably in any perl from 5.6.1 upwards and also in Solaris (and if you find any bug, I will try hard to correct it! :-).

    Note that you will have to install Expect if you want to use password authentication.

Re: SFTP perl script
by hipowls (Curate) on Apr 28, 2008 at 14:27 UTC

    The different perl versions will because the PATH environment variable is different for root and other users, your shell searches each directory in turn until it finds a perl. Try which perl to see where the perl you are using is located. Solaris installs perl and its libraries in /usr/perl5 with a copy of the executables in /usr/bin.

Re: SFTP perl script
by dwm042 (Priest) on Apr 28, 2008 at 19:28 UTC
    I've tried to get Net::SSH2 running in Solaris but the underlying libssh2 doesn't like to compile in Solaris. I have had better success with Net::SFTP::Foreign, which often works well when Net::SFTP simply hangs.

    As far as the different perls go, check the PATH variable as root and the user account. The command 'set' will usually list all your environment variables. If 'which' is supported by your shell, run 'which perl' in both environments.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://683289]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-18 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found