How to catch error messages in ftplib?

JL lightaiyee at gmail.com
Tue Nov 19 11:18:07 CET 2013


I have the following code;

    try:
        session = FTP(ftp_server_ip,ftp_user,ftp_password)
        file = open(filename,'rb') # file to send    
        session.storbinary('STOR ' +  filename, file) # send the file
    except Exception, errObj:
        print Exception
        print errObj
    file.close() # close file and FTP
    session.quit()

I deliberately placed an invalid ip address for the ftp_server_ip to see whether error messages can be caught. However, no exception was thrown. Can someone more experienced point to me what did I do wrong?

Thank you.



More information about the Python-list mailing list