Failed connection to sftp server via Net::SFTP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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!

#  Syntax:
#    perl  [user-id] [password] [file_name] [D]
use diagnostics;
use Net::SFTP;
use strict;

#   Constants:
    my $host = "";
    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\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";
    } 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;


[54]/home/jones: /opt/perl/bin/perl -w ./  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, port 22.
bobcat: Remote protocol version 2.0, remote software version
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 '' 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-
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/ line 85
    (W uninitialized) An undefined value was used as if it were
    defined.  It was interpreted as a "" or a 0, but maybe it was a
    To suppress this warning assign a defined value to your variables.

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

Use of uninitialized value in pack at
        /opt/perl/lib/site_perl/5.8.2/Net/SSH/Perl/ line 105
Uncaught exception from user code:
        Connection closed at ./ line 54
        Net::SFTP::get_msg('Net::SFTP=HASH(0x180074)') called at /opt/
perl/lib/site_perl/5.8.2/Net/ line 101
        Net::SFTP::do_init('Net::SFTP=HASH(0x180074)') called at /opt/
perl/lib/site_perl/5.8.2/Net/ line 43
id','ssh_args','ARRAY(0x14ba7c)',...) called at /opt/perl/lib/
site_perl/5.8.2/Net/ line 24
id','ssh_args',...) called at ./ line 54

Re: Failed connection to sftp server via Net::SFTP

Kevin13 wrote:
Quoted text here. Click to load it

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.

Re: Failed connection to sftp server via Net::SFTP

On Nov 17, 12:19=A0pm, "J. Gleixner" <glex_no-s...@qwest-spam-
no.invalid> wrote:
Quoted text here. Click to load it

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

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.

Site Timeline