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

NET SFTP disconnects

by DesmondL (Initiate)
on Apr 11, 2019 at 13:41 UTC ( #1232440=perlquestion: print w/replies, xml ) Need Help??
DesmondL has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have a script which successfully connects and downloads file from a remote sftp server however after three perhaps four connections when it tries to reconnect it fails and I've no idea why, its also for a client so I have no access to their SFTP server and have to rely on them for debug logs etc so its difficult, I finally got them to put it in to debug and see the following
00 9d 40 00 50 4b 05 06 00 00 00 00 01 00 01 00 e4 00 00 00 77 09 00 0 +0 18 00 50 4b 5a 49 50 20 | ..@.PK..............w.....PKZIP 66 6f 72 20 7a 2f 4f 53 20 62 79 20 50 4b 57 41 52 45 + | for z/OS by PKWARE #70267 1553268907.00000 _queue_msg: queueing msg len: 25, code:5, id: +188 ... [1] 00 00 00 19 05 00 00 00 bc 00 00 00 04 00 00 00 00 00 00 00 00 00 00 0 +a 89 00 00 0a 89 | ............................. #70267 1553268907.00000 _get_msg: waiting for message... [1] #70267 1553268907.00000 _do_io: _do_io connected: 1 #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268907.00000 _do_io: _do_io write queue: 29, syswrite: 29, + max: 65536, $!: 00 00 00 19 05 00 00 00 bc 00 00 00 04 00 00 00 00 00 00 00 00 00 00 0 +a 89 00 00 0a 89 | ............................. #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268907.00000 _do_io: _do_io read sysread: 34, total read: +34, $!: 00 00 00 1e 65 00 00 00 bc 00 00 00 01 00 00 00 0b 45 6e 64 20 6f 66 2 +0 66 69 6c 65 00 00 00 02 | ....e............End of file.... 65 6e + | en #70267 1553268907.00000 _get_msg: got it!, len:30, code:101, id:188, +status: 1 65 00 00 00 bc 00 00 00 01 00 00 00 0b 45 6e 64 20 6f 66 20 66 69 6c 6 +5 00 00 00 02 65 6e | e............End of file....en #70267 1553268907.00000 _set_status: _set_status code: 1, str: End of + file #70267 1553268907.00000 _set_error: _set_err code: 5, str: Couldn't r +ead from remote file: End of file #70267 1553268907.00000 DESTROY: Net::SFTP::Foreign::FileHandle=GLOB( +0x237b5d0)->DESTROY called (sftp: Net::SFTP::Foreign=HASH(0x2375828)) #70267 1553268907.00000 _queue_msg: queueing msg len: 13, code:4, id: +189 ... [1] 00 00 00 0d 04 00 00 00 bd 00 00 00 04 00 00 00 00 + | ................. #70267 1553268907.00000 _get_msg: waiting for message... [1] #70267 1553268907.00000 _do_io: _do_io connected: 1 #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268907.00000 _do_io: _do_io write queue: 17, syswrite: 17, + max: 65536, $!: 00 00 00 0d 04 00 00 00 bd 00 00 00 04 00 00 00 00 + | ................. #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268907.00000 _do_io: _do_io read sysread: 30, total read: +30, $!: 00 00 00 1a 65 00 00 00 bd 00 00 00 00 00 00 00 07 53 75 63 63 65 73 7 +3 00 00 00 02 65 6e | ....e............Success....en #70267 1553268907.00000 _get_msg: got it!, len:26, code:101, id:189, +status: 0 65 00 00 00 bd 00 00 00 00 00 00 00 07 53 75 63 63 65 73 73 00 00 00 0 +2 65 6e | e............Success....en #70267 1553268907.00000 _close: closing file handle, return: 1, rid: 00 00 00 00 + | .... #70267 1553268907.00000 DESTROY: Net::SFTP::Foreign=HASH(0x2375828)-> +DESTROY called (current pid: 70267, disconnect_by_pid: 70267), curren +t thread generation: 1, disconnect_by_thread: 1) #70267 1553268907.00000 disconnect: Net::SFTP::Foreign=HASH(0x2375828 +)->disconnect called (ssh pid: 70272) #70267 1553268907.00000 _conn_lost: _conn_lost #70267 1553268907.00000 _set_status: _set_status code: 7, str: Connec +tion lost #70267 1553268907.00000 _set_error: _set_err code: 37, str: Connectio +n to remote server is broken #70267 1553268907.00000 disconnect: starting dirty cleanup of process + 70272 #70267 1553268907.00000 disconnect: killing process 70272 with signal + 0 #70267 1553268907.00000 disconnect: waitpid returned 0 #70267 1553268907.00000 disconnect: waitpid returned 70272 #70267 1553268907.00000 disconnect: process 70272 reaped .... 03/22/2019 11:35:07 INFO: Looking for fares to#70267 1553268907.00000 +new: This is Net::SFTP::Foreign 1.90 #70267 1553268907.00000 new: Loaded from /home/jbinst/perl5/lib/perl5 +/Net/SFTP/Foreign.pm #70267 1553268907.00000 new: Running on Perl v5.10.1 for linux #70267 1553268907.00000 new: debug set to -1 #70267 1553268907.00000 new: ~0 is 18446744073709551615 #70267 1553268907.00000 new: Using backend Net::SFTP::Foreign::Backen +d::Unix 1.88_02 #70267 1553268907.00000 autodisconnect: setting disconnecting pid to +70267 and thread to 1 #70267 1553268907.00000 _init_transport: ssh cmd: ssh -o PreferredAut +hentications=publickey fareloader@10.60.96.19 -s sftp Proceeding to download missing files. Attempting to connect to the SFTP server as: @ 10.60.96.19 #70267 1553268907.00000 _queue_msg: queueing msg len: 5, code:1, id:3 + ... [1] 00 00 00 05 01 00 00 00 03 + | ......... #70267 1553268907.00000 _get_msg: waiting for message... [1] #70267 1553268907.00000 _do_io: _do_io connected: 1 #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268907.00000 _do_io: _do_io write queue: 9, syswrite: 9, m +ax: 65536, $!: 00 00 00 05 01 00 00 00 03 + | ......... #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268917.00000 _do_io: _do_io select failed: #70267 1553268917.00000 _conn_lost: _conn_lost #70267 1553268917.00000 _set_status: _set_status code: 7, str: Connec +tion lost #70267 1553268917.00000 _set_error: _set_err code: 37, str: Connectio +n to remote server stalled #70267 1553268917.00000 _queue_msg: queueing msg len: 26, code:16, id +:0 ... [2] 00 00 00 1a 10 00 00 00 00 00 00 00 11 2f 48 6f 6d 65 2f 61 74 70 63 6 +f 2f 46 61 72 65 73 #70267 1553268917.00000 _get_msg: waiting for message... [2] #70267 1553268917.00000 _do_io: _do_io connected: 0 #70267 1553268917.00000 _conn_lost: _conn_lost #70267 1553268917.00000 _set_status: _set_status code: 7, str: Connec +tion lost #70267 1553268917.00000 _rel2abs: '' --> '.' #70267 1553268917.00000 _queue_msg: queueing msg len: 10, code:16, id +:1 ... [3] 00 00 00 0a 10 00 00 00 01 00 00 00 01 2e + | .............. #70267 1553268917.00000 _get_msg: waiting for message... [3] #70267 1553268917.00000 _do_io: _do_io connected: 0 #70267 1553268917.00000 _conn_lost: _conn_lost :

Replies are listed 'Best First'.
Re: NET SFTP disconnects
by salva (Abbot) on Apr 11, 2019 at 14:37 UTC
    Enable debugging on the ssh process adding the arguments more => '-vvv' into the constructor call.

    Update: In any case the problem seems to be that you have set a timeout of 10 seconds and the server is not responding in that time:

    #70267 1553268907.00000 _do_io: _do_io select(-,-,-, 10) #70267 1553268917.00000 _do_io: _do_io select failed: #70267 1553268917.00000 _conn_lost: _conn_lost
Re: NET SFTP disconnects
by DesmondL (Initiate) on Apr 11, 2019 at 16:12 UTC
    Hi Salva Thanks for that I asked a client for a copy of the script to see if they had amended it and found they had changed the following line after you pointed out the 10 seconds timeout also its using a password not a public key! I'm hoping that will solve the issue # attempt connecton to SFTP site #$sftp = Net::SFTP::Foreign->new( $username . '@' . $sftpServer, timeout => 60, password => $password); $sftp = Net::SFTP::Foreign->new( $username . '@' . $sftpServer, timeout => 10, more => -o => 'PreferredAuthentications=publickey');

      Hello DesmondL,

      Welcome to the Monastery. I am not the expert here (far from that), fellow Monk salva is. If I am not mistaken he also is the author of the package Net::SFTP::Foreign.

      Having said that, I would propose to modify the script with the following part:

      my %args = ( host => "localhost", user => "user", port => "22", # psw => "psw", more => [qw(-o PreferredAuthentications=publickey)], key_path => "/home/user/.ssh/id_rsa" ); my $sftp = Net::SFTP::Foreign->new(%args); $sftp->die_on_error("Unable to establish SFTP connection");

      Modify the parameters to your needs.

      Hope this helps, BR

      Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2019-04-20 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (109 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!