3

I'm trying to send some files via pysftp, authentication seems fine, but actually putting the file results in it hanging, doing nothing. The files are small (<200kb) so I don't believe it's an upload issue (internet access is fine). Eventually the connection times out.

Code:

if os.listdir(ftp_path):# only do if files are there
    with pysftp.Connection(FTP_SERVER,
                             port=FTP_PORT
                             username=FTP_USER, 
                             private_key=FTP_SSH_PRIVATE_KEY_PATH
    ) as sftp:
        with sftp.cd(FTP_REMOTE_FOLDER):
            for f in os.listdir(ftp_path):
                if os.path.isfile(os.path.join(ftp_path,f)) :
                    # upload image to server
                    self.log.info("HB FTP, Start upload: "+f)
                    print(ftp_path+"\\"+f)
                    sftp.put(os.path.join(ftp_path,f))
                    self.log.info("HB FTP, Finished Upload: "+f)

Logging output here:

FSW_COMMS paramiko.transport 01/24/2015 04:23:58 PM: INFO: Authentication (publickey) successful!
FSW_COMMS paramiko.transport 01/24/2015 04:23:58 PM: DEBUG: [chan 1] Max packet in: 32768 bytes
FSW_COMMS paramiko.transport 01/24/2015 04:23:58 PM: DEBUG: [chan 1] Max packet out: 0 bytes
FSW_COMMS paramiko.transport 01/24/2015 04:23:58 PM: DEBUG: Secsh channel 1 opened.
FSW_COMMS paramiko.transport 01/24/2015 04:23:58 PM: DEBUG: [chan 1] Sesch channel 1 request ok
FSW_COMMS paramiko.transport.sftp 01/24/2015 04:23:58 PM: INFO: [chan 1] Opened sftp connection (server version 3)
FSW_COMMS paramiko.transport.sftp 01/24/2015 04:23:58 PM: DEBUG: [chan 1] normalize('.')
FSW_COMMS paramiko.transport.sftp 01/24/2015 04:23:58 PM: DEBUG: [chan 1] stat('files')
FSW_COMMS paramiko.transport.sftp 01/24/2015 04:23:58 PM: DEBUG: [chan 1] normalize('files')
FSW_COMMS root 01/24/2015 04:23:58 PM: INFO: HB FTP, Start upload: 2015-01-17-19-37-07.jpg
FSW_COMMS paramiko.transport.sftp 01/24/2015 04:23:58 PM: DEBUG: [chan 1] open('/files/2015-01-17-19-37-07.jpg', 'wb')
FSW_COMMS paramiko.transport.sftp 01/24/2015 04:23:58 PM: DEBUG: [chan 1] open('/files/2015-01-17-19-37-07.jpg', 'wb') -> 34613039393262343666383036653839

Any help or pointers on how to debug further much appreciated,

Jules

  • Not sure if this is relevant but put in paramiko usually requires two arguments `sftp.put( localpath, remotepath)` I would think that the above would raise an exception – chaps Jan 25 '15 at 15:27
  • Thanks Ben, I've tested this, it makes no difference, and the code as above does run without exception – Jules Stevenson Jan 25 '15 at 15:41
  • Are you on Windows? Maybe some function like `put()` is getting confused with the backslashes in the path name. If it tries to send backslashes over the SFTP server, it can cause confusion. – Armin Rigo Jan 26 '15 at 12:00
  • have you had any breakthroughs on this issue? I'm going through the same problems right now. – Zihs Mar 26 '15 at 18:37
  • Hey Jules, I've had a similar error and I might be able to help but I need a little more information. After the connection times out, was any portion of your file uploaded to the SFTP? Using a packet sniffing tool like `ngrep` or `tcpdump`, is there a lot of network traffic (greater than 100 lines)? – Cawb07 Apr 30 '15 at 18:10
  • Having the same problem. Similarly I create a file with SFTPServer.open then write data from a stream. It hangs. Shutting down the server would leave a python process running. I'm running into this issue on mac. – Khanh Hua Jun 05 '15 at 23:40

1 Answers1

0

This appears to be a bug in the version of Paramiko you are using (I suspect 1.15.1 or older): https://lists.nongnu.org/archive/html/duplicity-talk/2015-05/msg00023.html

Upgrading to 1.15.4 solved the issue for me.

devurandom
  • 111
  • 1
  • 4