FTPS ( FTP over SSL) Problem with Python's builtin SSL

Robert k.robert at gmx.de
Sat Jun 5 00:15:10 CEST 2004


I need to run FTP over SSL from windows (not shitty sftp via ssh etc!)
as explained on
http://www.ford-hutchinson.com/~fh-1-pfh/ftps-ext.html (good variant
3: FTP_TLS )

I tried to learn from M2Crypto's ftpslib.py (uses OpenSSL - not
Pythons SSL) and made a wrapper for ftplib.FTP using Pythons SSL.

I wrap the cmd socket like:

        self.voidcmd('AUTH TLS')
        ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
        import httplib
        self.sock = httplib.FakeSocket(self.sock, ssl)
        self.file = self.sock.makefile('rb')

Everything works ok, if I don't SSL the data port connection, but only
the
If I SSL the data port connection too, it almosts work, but ...

        self.voidcmd('PBSZ 0')
        self.voidcmd('PROT P')

wrap the data connection with SSL:

            ssl = socket.ssl(conn, self.key_file, self.cert_file)
            import httplib
            conn = httplib.FakeSocket(conn, ssl)

than in retrbinary it hangs endless in the last 'return
self.voidresp()'. all data of the retrieved file is already correctly
in my basket! The ftp server just won't send the final '226 Transfer
complete.' on the cmd socket. Why?

    def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
        self.voidcmd('TYPE I')
        conn = self.transfercmd(cmd, rest)
        fp = conn.makefile('rb')
        while 1:
            #data = conn.recv(blocksize)
            data = fp.read()    #blocksize)
            if not data:
                break
            callback(data)
        fp.close()
        conn.close()
        return self.voidresp()


what could be reason? 
The server is a ProFTPD 1.2.9 Server.
I debugged, that the underlying (Shared)socket of the conn object is
really closed.
(If I simly omit the self.voidresp(), I have one file in the box, but
subsequent ftp communication on that connection is not anymore
correct.)

Someone else has already made this FTP over Python's SSL?

Robert



More information about the Python-list mailing list