Failed connection to sftp server via Net::SFTP

K

Kevin13

Hi. Following perl code fails to connect to SFTP server (user-id/
password authentication only supported on the server). Has
consistently worked for last year, so likely a change on far end.
Looking for some clue to pass along to techs that support the sftp
server. Diagnostic messages follow code.

Any thoughts or insights would be much appreciated!


#!/opt/perl/bin/perl
#
# Syntax:
#
# perl sftp_dbg.pl [user-id] [password] [file_name] [D]
#
#
use diagnostics;
use Net::SFTP;
use strict;

# Constants:
my $host = "xxx.xxx.gov.uk";
my $path = "/report_upload";

# Read command line for rest:
my $userid = shift @ARGV;
my $passwd = shift @ARGV;
my $trsfile = shift @ARGV;
my $debug = shift @ARGV;

# Debug mode?
($debug =~ "[Dd]") ? ($debug = "true") : ($debug = "false");

# Set up sftp params:
my %args = (
user => $userid,
password => $passwd,
debug => $debug,
ssh_args => [port => 22] );

my $localfile = $trsfile;
my $remotefile = $path . "/" . $trsfile;


# Main:

print "\nUploading ", $localfile, " to ", $remotefile, "...\n\n";

if ($debug eq "true") {
print "Contents of '\%args' hash:\n";
foreach my $key (keys %args) {
print "At $key we have $args{$key}\n";
}
print "\n";
}


my $sftp = Net::SFTP->new($host, %args);
print "Session opened...\n\n";


# Contrary to documentation, returns zero (false) on success; "true"
on error.
if (!($sftp->put($localfile, $remotefile))) {
print "\nFile uploaded successfully...\n";
### print "\nTRUE status received...\n";
exit;
} else {
# Note: Depending on error, script may just choke here. But
still sets $status flag.
print "\nERROR: File NOT uploaded!\n";
### print "\nFALSE status received...\n";
exit 1;
}




Output:

[54]/home/jones: /opt/perl/bin/perl -w ./sftpTRSdbg.pl user-id
password testfile.txt D

Uploading testfile.txt to /report_upload/testfile.txt...

Contents of '%args' hash:
At password we have password
At debug we have true
At user we have user-id
At ssh_args we have ARRAY(0x14ba7c)

bobcat: Reading configuration data /home/jones/.ssh/config
bobcat: Reading configuration data /etc/ssh_config
bobcat: Connecting to xxx.xxx.gov.uk, port 22.
bobcat: Remote protocol version 2.0, remote software version
ReflectionForSecureIT_7.1.0.246
bobcat: Net::SSH::perl Version 1.24, protocol version 2.0.
..obcat: No compat match: ReflectionForSecureIT_7.1.0.246
bobcat: Connection established.
bobcat: Sent key-exchange init (KEXINIT), wait response.
bobcat: Algorithms, c->s: 3des-cbc hmac-sha1 none
bobcat: Algorithms, s->c: 3des-cbc hmac-sha1 none
bobcat: Entering Diffie-Hellman Group 1 key exchange.
bobcat: Sent DH public key, waiting for reply.
bobcat: Received host key, type 'ssh-dss'.
bobcat: Host 'xxx.xxx.gov.uk' is known and matches the host key.
bobcat: Computing shared secret key.
bobcat: Verifying server signature.
bobcat: Waiting for NEWKEYS message.
bobcat: Enabling incoming encryption/MAC/compression.
bobcat: Send NEWKEYS, enable outgoing encryption/MAC/compression.
bobcat: Sending request for user-authentication service.
bobcat: Service accepted: ssh-userauth.
bobcat: Trying empty user-authentication request.
bobcat: Authentication methods that can continue: publickey,keyboard-
interactive,password.
bobcat: Next method to try is publickey.
bobcat: Next method to try is password.
bobcat: Trying password authentication.
bobcat: Login completed, opening dummy shell channel.
bobcat: channel 0: new [client-session]
bobcat: Requesting channel_open for channel 0.
bobcat: channel 0: open confirm rwindow 0 rmax 32768
bobcat: Got channel open confirmation, requesting shell.
bobcat: Requesting service shell on channel 0.
bobcat: channel 1: new [client-session]
bobcat: Requesting channel_open for channel 1.
bobcat: channel 0: rcvd eof
bobcat: channel 0: output open -> drain
bobcat: channel 0: rcvd close
bobcat: channel 0: input open -> closed
bobcat: channel 0: close_read
bobcat: channel 0: obuf empty
bobcat: channel 0: output drain -> closed
bobcat: channel 0: close_write
bobcat: channel 0: send close
bobcat: channel 0: full closed
bobcat: sftp: Sending SSH2_FXP_INIT
Use of uninitialized value in numeric gt (>) at
/opt/perl/lib/site_perl/5.8.2/Net/SSH/Perl/Channel.pm line 85
(#1)
(W uninitialized) An undefined value was used as if it were
already
defined. It was interpreted as a "" or a 0, but maybe it was a
mistake.
To suppress this warning assign a defined value to your variables.

To help you figure out what was undefined, perl tells you what
operation
you used the undefined value in. Note, however, that perl
optimizes your
program and the operation displayed in the warning may not
necessarily
appear literally in your program. For example, "that $foo" is
usually optimized into "that " . $foo, and the warning will refer
to
the concatenation (.) operator, even though there is no . in your
program.

Use of uninitialized value in pack at
/opt/perl/lib/site_perl/5.8.2/Net/SSH/Perl/Buffer.pm line 105
(#1)
Uncaught exception from user code:
Connection closed at ./sftpTRSdbg.pl line 54
Net::SFTP::get_msg('Net::SFTP=HASH(0x180074)') called at /opt/
perl/lib/site_perl/5.8.2/Net/SFTP.pm line 101
Net::SFTP::do_init('Net::SFTP=HASH(0x180074)') called at /opt/
perl/lib/site_perl/5.8.2/Net/SFTP.pm line 43
Net::SFTP::init('Net::SFTP=HASH
(0x180074)','password','password','debug','true','user','user-
id','ssh_args','ARRAY(0x14ba7c)',...) called at /opt/perl/lib/
site_perl/5.8.2/Net/SFTP.pm line 24
Net::SFTP::new
('Net::SFTP','xxx.xxx.gov.uk','password','password','debug','true','user','user-
id','ssh_args',...) called at ./sftpTRSdbg.pl line 54
[55]/home/jones/:
 
J

J. Gleixner

Kevin13 said:
Hi. Following perl code fails to connect to SFTP server (user-id/
password authentication only supported on the server). Has
consistently worked for last year, so likely a change on far end.
Looking for some clue to pass along to techs that support the sftp
server. Diagnostic messages follow code.

Any thoughts or insights would be much appreciated!

Since you say your program hasn't changed, then why do you
think there's a problem there?

Start by testing if you can get to the server and do everything
via the command line.
 
K

Kevin13

Since you say your program hasn't changed, then why do you
think there's a problem there?

Start by testing if you can get to the server and do everything
via the command line.

"Looking for some clue to pass along to techs that support the sftp
server."

Yes, I am able to run sftp from the command line and successfully
connect to the server, transfer file, etc. Sorry, thought I mentioned
that. Again, I do *not* think there is a problem with my program.
But, regardless I am being looked to to solve the issue and
unfortunately that likely means I have to "convince" the support staff
at the other end that there really is an issue.
 
K

Kevin13

Okay, if anyone else should run into a similar situation, look to the
version of perl that you're using and/or the versions of the specific
modules installed.

For example in this case the issue was the use of perl package
"Net::SSH::perl" (which underlies "Net::SFTP"). In our installation
the former module was version 1:24. Versions 1:30 and later were
proved to work properly. (Yes, we should keep our perl installation
up to date. Not something I have any control over.)

The folks at the other end had been upgrading the software
configuration on their sftp server which evidently suddenly caused our
code to fail. Here's a little more:

"The failure consistently happens when channel 0 of the SSH dialogue
receives an end-of-file and the failure does not happen if the user
has the shell set to /usr/bin/ssh-dummy-shell, as was used with the
pre-upgrade Reflections SSH, rather than the /usr/bin/false now
employed for security reasons with the upgraded version."

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top