0

I have a problem connecting via SSH to a WS-FTP server using Python3 ftplib for the client.

Here's a small example:

import ftplib
sess = ftplib.FTP_TLS()
sess.connect(<hostname>, 22)

This just hangs in sess.connect. Here's the traceback from connect():

Traceback (most recent call last):
  File "o:/Thy.Python/logls.py", line 19, in <module>
    logs = u.newSession()
  File "/cygdrive/o/Thy.Python/logutils.py", line 41, in newSession
    sess.connect(findsys(), 22)
  File "/usr/lib/python3.6/ftplib.py", line 155, in connect
    self.welcome = self.getresp()
  File "/usr/lib/python3.6/ftplib.py", line 234, in getresp
    resp = self.getmultiline()
  File "/usr/lib/python3.6/ftplib.py", line 224, in getmultiline
    nextline = self.getline()
  File "/usr/lib/python3.6/ftplib.py", line 202, in getline
    line = self.file.readline(self.maxline + 1)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)

Wireshark shows this:

2017-06-14 11:26:21.623858 <Client> <Server> TCP 66 57092 › 22 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
2017-06-14 11:26:21.625280 <Server> <Client> TCP 62 22 › 57092 [SYN, ACK] Seq=0 Ack=1 Win=4380 Len=0 MSS=1460 SACK_PERM=1
2017-06-14 11:26:21.625428 <Client> <Server> TCP 54 57092 › 22 [ACK] Seq=1 Ack=1 Win=64240 Len=0
2017-06-14 11:26:21.649362 <Server> <Client> SSH 78 Server: Protocol (SSH-2.0-WS_FTP-SSH_7.7)
2017-06-14 11:26:21.843439 <Client> <Server> TCP 54 57092 › 22 [ACK] Seq=1 Ack=25 Win=64216 Len=0

Two things stand out:

  • ftplib() (or its subordinate libraries) doesn't appear to send an SSH Client: Protocol message
  • After the server responds with its Server: Protocol message, ftplib just sends an ACK and doesn't initiate key exchange.

Can anyone suggest what's happening, and how to fix it? I'm afraid I'm on the cliff-edge of my competence here.

Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62

1 Answers1

0

It turns out that the server is an SFTP server, not FTPS. Answers to this question suggest Paramiko or Twisted

Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62