How to catch error messages in ftplib?
JL
lightaiyee at gmail.com
Tue Nov 19 05:20:31 EST 2013
I repost the original code segment to make it more complete;
from ftplib import FTP
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()
On Tuesday, November 19, 2013 6:18:07 PM UTC+8, JL wrote:
> 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