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

Discussion in 'Python' started by Robert, Jun 4, 2004.

  1. Robert

    Robert Guest

    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
    Robert, Jun 4, 2004
    #1
    1. Advertising

  2. Robert

    fishboy Guest

    fishboy, Jun 6, 2004
    #2
    1. Advertising

  3. Robert

    Robert Guest

    fishboy <> wrote in message news:<>...
    > On 4 Jun 2004 15:15:10 -0700, (Robert) wrote:
    >
    > >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'm curious. How is sftp bad for you?
    >
    > ><{{{*>


    SFTP is not "generally bad" (depends on specific case). Yet, it isn't
    FTP at all, but uses the unix logon and fakes commands which to do
    "something like FTP".
    I need real portable FTP only relying on an FTP server. And most
    modern FTP servers support FTP over SSL/TLS. An this is widely
    considered to be the most "correct" solution.

    Still couldn't solve the hang.

    I assume somehow the socket with SSL attached does not close correct
    in Python's SSL implementation - and this bug doesn't show with normal
    sessions like https-urlopen because no one takes care what happens
    after the session. Yet the FTP data channel needs to be closed
    correctly to trigger a "transfer completed" on the control channel.
    What could I do?

    Robert
    Robert, Jun 10, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,563
    iksrazal
    Apr 25, 2004
  2. Alexander Avtanski

    Free FTPS client implementation?

    Alexander Avtanski, Mar 1, 2006, in forum: Java
    Replies:
    4
    Views:
    10,077
  3. Russell E. Owen

    trouble with urllib and ftps

    Russell E. Owen, Nov 17, 2004, in forum: Python
    Replies:
    0
    Views:
    334
    Russell E. Owen
    Nov 17, 2004
  4. bdb112
    Replies:
    2
    Views:
    289
    Chris Torek
    Jul 2, 2011
  5. D. Buck
    Replies:
    2
    Views:
    459
    D. Buck
    Jun 29, 2004
Loading...

Share This Page