Operating System - Linux
1759202 Members
2510 Online
108881 Solutions
New Discussion юеВ

Re: Help with Perl Net::SFTP module

 
SOLVED
Go to solution
TwoProc
Honored Contributor

Help with Perl Net::SFTP module

I'm trying to use the Net::SFTP script (and I'm pretty bad at Perl too, but trying to learn it). To tell you the truth, this is running on Linux, not on HPUX (I couldn't get Net::SFTP to fully compile and install on HPUX, but tried for weeks). But, I couldn't find a "languages and scripting" forum there... Hopefully, this is close enough.

I can use this package pretty well, except when I try to use a non-standard port number for the sftp server, instead of the default ssh number of 22, then it fails. I've attached the code segment and debug output below. Also, for the port number argument, I've tried both '563' and 563 - amazingly enough, they both end up having the same error, I thought I would have at least had a parameter data type problem before or after the change.

Example code:

#!/usr/bin/perl -w

use Net::SFTP;
use strict;

my $host = "someserver.com";
my %args = (
user => 'myusername',
password => 'mypassword',
port => 563,
debug => 'true'
);

# Make connection
my $sftp = Net::SFTP->new($host, %args);

My problem is that when I try to connect to this thing, - according to debug, it is still going to connect to port 22. Even stranger, it seems to communicate with the thing and swap id keys successfully, but it fails in the end...

Here is the debug output: *notice that on the third line, it says that it is connecting to port 22. Either it is ignoring my parmater and connecting to 22 by default and that's why it fails (no user account there), or this is just a "bug in debug" where it isn't really connecting to 22 at all, it just says it is?

Any suggestions appreciated.

svrA: Reading configuration data /home/someuser/.ssh/config
svrA: Reading configuration data /etc/ssh_config
svrA: Connecting to someserver.com, port 22.
svrA: Remote version string: SSH-2.0-OpenSSH_4.2

svrA: Remote protocol version 2.0, remote software version OpenSSH_4.2
svrA: Net::SSH::Perl Version 1.30, protocol version 2.0.
svrA: No compat match: OpenSSH_4.2.
svrA: Connection established.
svrA: Sent key-exchange init (KEXINIT), wait response.
svrA: Algorithms, c->s: 3des-cbc hmac-sha1 none
svrA: Algorithms, s->c: 3des-cbc hmac-sha1 none
svrA: Entering Diffie-Hellman Group 1 key exchange.
svrA: Sent DH public key, waiting for reply.
svrA: Received host key, type 'ssh-dss'.
svrA: Host 'someserver.com' is known and matches the host key.
svrA: Computing shared secret key.
svrA: Verifying server signature.
svrA: Waiting for NEWKEYS message.
svrA: Enabling incoming encryption/MAC/compression.
svrA: Send NEWKEYS, enable outgoing encryption/MAC/compression.
svrA: Sending request for user-authentication service.
svrA: Service accepted: ssh-userauth.
svrA: Trying empty user-authentication request.
svrA: Authentication methods that can continue: publickey,keyboard-interactive.
svrA: Next method to try is publickey.
svrA: Trying pubkey authentication with key file '/home/someuser/.ssh/id_dsa'
svrA: Authentication methods that can continue: publickey,keyboard-interactive.
svrA: Next method to try is publickey.
Permission denied at /usr/lib/perl5/site_perl/5.8.0/Net/SFTP.pm line 62

One more note: this is Perl 5.8.0, and I've installed the latest CPAN module and from there installed the latest Net::SFTP I could find on the mirrors.

Can anyone with a working Net::SFTP module in Perl try this too? Other ideas?

thanks in advance.
We are the people our parents warned us about --Jimmy Buffett
4 REPLIES 4
Peter Godron
Honored Contributor
Solution

Re: Help with Perl Net::SFTP module

John,
from another site:
my $sftp = new Net::SFTP( $host, user=>$user, password=>$pass,
debug=>true, ssh_args => [ port => '2300' ] );
TwoProc
Honored Contributor

Re: Help with Perl Net::SFTP module

Thanks Peter,

That was exactly it! I'm guessing that the rest of the args other user, password, and debug had to live in a sub-list (sub-array).

This worked great, thank you very much.
We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: Help with Perl Net::SFTP module

Solution was to change my code in this section:

my %args = (
user => 'myusername',
password => 'mypassword',
port => 563,
debug => 'true'
);

to

my %args = (
user => 'myusername',
password => 'mypassword',
debug => 'true',
ssh_args => [port => 563]
);

----------------------------------------
Final code looks like:
----------------------------------------
#!/usr/bin/perl -w

use Net::SFTP;
use strict;

my $host = "someserver.com";
my %args = (
user => 'myusername',
password => 'mypassword',
debug => 'true',
ssh_args => [port => 563],
);

# Make connection
my $sftp = Net::SFTP->new($host, %args);
----------------------------------------
We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: Help with Perl Net::SFTP module

Thanks Peter.

See comment above for fix.
We are the people our parents warned us about --Jimmy Buffett