Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

capturing FTP server replies

Status
Not open for further replies.

eclecticNancy

Programmer
May 18, 2007
19
US
I'm trying to access a server using FTP/SSL. I am using ftplib but don't have an ssl library (suggestions?) - In fact, any FTP/SSL help is welcome but my primary question here is more general.

I'm running interactive within PythonWin. I'm able to capture some of the server replies, but I think there are more. (I've been unable to duplicate from command prompt because with Py I know how to send additional commands before USER/PASS but I don't know how to do that from cmd.)

Here's what I've written:
Code:
    from ftplib import FTP

    print 'starting ftp'
    m = ftp = FTP()
    print m
    success = 1
    
    try:
        print 'ftp.connect(serverName, portNum)'        
        m = ftp.connect(serverName, portNum)
        print m
    except:
        print "Couldn't find server"
        success = 0
    if success:
        try:
            print "ftp.sendcmd('AUTH SSL')"
            m = ftp.sendcmd('AUTH SSL')
            print m
        except:
            print 'failed'
            success = 0          
    if success:
        try:
            print "ftp.sendcmd('USER ' + userName)"
            m = ftp.sendcmd('USER ' + userName)
            print m
        except:
            print 'USER ' + userName
            print 'login failed'
            success = 0

Here's what I see (with my username at xxxxxx):
(I'm using code tags to set it apart but it's the output)
Code:
starting ftp
<ftplib.FTP instance at 0x0162EA30>
ftp.connect(serverName, portNum)
220-Hello, Welcome to SecureTransport!
220-
220 Secure FTP Server ready.
ftp.sendcmd('AUTH SSL')
334 SSLv23/TLSv1
ftp.sendcmd('USER' + userName)
USER xxxxxx
login failed

Thanks for any help,

Nancy
 
do not have a secure FTP site to test on but try

Code:
>>> import ftplib
>>> help(ftplib.FTP.set_debuglevel)
Help on method set_debuglevel in module ftplib:

set_debuglevel(self, level) unbound ftplib.FTP method
    Set the debugging level.
    The required argument level means:
    0: no debugging output (default)
    1: print commands and responses but not body text etc.
    2: also print raw lines read and sent before stripping CR/LF

>>> c = ftplib.FTP()
>>> c.set_debuglevel(2)
>>> c.connect('sp0234')
*get* '220-FileZilla Server version 0.9.12 beta\r\n'
*get* '220-written by Tim Kosse (Tim.Kosse@gmx.de)\r\n'
*get* '220 Please visit [URL unfurl="true"]http://sourceforge.net/projects/filezilla/\r\n'[/URL]
*resp* '220-FileZilla Server version 0.9.12 beta\n220-written by Tim Kosse (Tim.Kosse@gmx.de)\n220 Please visit [URL unfurl="true"]http://sourceforge.net/projects/filezilla/'[/URL]
'220-FileZilla Server version 0.9.12 beta\n220-written by Tim Kosse (Tim.Kosse@gmx.de)\n220 Please visit [URL unfurl="true"]http://sourceforge.net/projects/filezilla/'[/URL]
>>> c.login('justin', '*****')
*cmd* 'USER justin'
*put* 'USER justin\r\n'
*get* '331 Password required for justin\r\n'
*resp* '331 Password required for justin'
*cmd* 'PASS ***********'
*put* 'PASS ***********\r\n'
*get* '230 Logged on\r\n'
*resp* '230 Logged on'
'230 Logged on'
>>> c.quit()
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '221 Goodbye\r\n'
*resp* '221 Goodbye'
'221 Goodbye'
>>> c.close()
>>>
 
Things got busy and I set this aside but am looking at it again today.

Your suggestion worked great. I'm still not able to connect but am getting the server replies - so thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top