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

Hi perl experts I need your help, I'm trying to use net::sftp::foreign to sftp-"put" a file onto a network device but stumbled onto an error. Code :

sub cleanExit { my( $Sftp, $errstr, $errcode) = @_; print STDERR "ERROR: $errstr\n"; # $Sftp->quit(); exit $errcode; } sub DoTransfer { my ($srcfile, $sourcedir, $Sftpip,$destdir) = @_; my $Sftp = Net::SFTP::Foreign->new( $Sftpip,user => $SFTPUSER +,password => $SFTPPASSWD, "more" => '-v' , ); if( !defined( $Sftp)) { cleanExit( $Sftp, "Cannot open FTP session", 2); } if( !$Sftp->put( "$sourcedir/$srcfile", "$destdir/$srcfile") +) { #-- cannot put file cleanExit( $Sftp, "Cannot upload $srcfile ", 5); } }

File transfer fails and cleanexit gets called. A message "Use of uninitialized value $_[0] in join or string at /usr/local/share/perl5/Net/SFTP/Foreign/Common.pm line 41." is in the below are the output

perl copyXmlToExternalSftp.pl --xmlfile XMLG2WF007 --sourcedir /opt/si +pTL1/XMLs --ftpip 10.242.251.26 --destdir /pub/OntSw/Download OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: Connecting to 10.242.251.26 [10.242.251.26] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: identity file /root/.ssh/id_rsa type -1 debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: identity file /root/.ssh/id_dsa type -1 debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: identity file /root/.ssh/id_ed25519 type -1 debug1: identity file /root/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1 debug1: Remote protocol version 2.0, remote software version IPSSH-1.1 +2.0 debug1: no match: IPSSH-1.12.0 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: kex: diffie-hellman-group14-sha1 need=16 dh_need=16 debug1: kex: diffie-hellman-group14-sha1 need=16 dh_need=16 debug1: sending SSH2_MSG_KEXDH_INIT debug1: expecting SSH2_MSG_KEXDH_REPLY debug1: Server host key: RSA a6:7c:23:0d:fc:ab:81:fb:87:72:ba:62:b9:94 +:f7:bb debug1: Host '10.242.251.26' is known and matches the RSA host key. debug1: Found key in /root/.ssh/known_hosts:5 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: password debug1: Next authentication method: password debug1: Authentication succeeded (password). Authenticated to 10.242.251.26 ([10.242.251.26]:22). debug1: channel 0: new [client-session] debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 debug1: Sending subsystem: sftp Use of uninitialized value $_[0] in join or string at /usr/local/share +/perl5/Net/SFTP/Foreign/Common.pm line 41. ERROR: Cannot upload XMLG2WF007 debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK Transferred: sent 2928, received 1888 bytes, in 0.2 seconds Bytes per second: sent 15231.8, received 9821.6 debug1: Exit status -1

Replies are listed 'Best First'.
Re: put net::sftp::foreign getting error
by FredDoOrDie (Initiate) on Nov 21, 2018 at 03:18 UTC

    I made a noob mistake, instead of downloading and installing the latest net::sftp::foreign ver 1.89, I downloaded the 1.69 version I then added the following argument best_effort => 1 to put and now it put operation is okay

     $Sftp->put( "$sourcedir/$srcfile", "$destdir/$srcfile", best_effort => 1)