我正在編寫一個應用程序,該應用程序應該將文件上載到FTP服務器。如何在Python中使用FTPlib
下面的代碼:
try:
f = open(filename,"rb")
except:
print "error 0"
try:
ftp = FTP(str(self.ConfigUri))
print "CONNECTED!"
except:
print "CANNOT CONNECT"
try:
ftp = FTP(str(self.ConfigUri)) # connect to host, default port
except:
print "error 1"
try:
ftp.login() # user anonymous, passwd [email protected]
except:
print "error2"
try:
ftp.storbinary('STOR ' + filename, f)
except:
print "error 3"
try:
ftp.quit()
except:
print "error 4"
我得到一個錯誤的ftp.storbinary( 'STOR' +文件名,F)。任何想法爲什麼?
嘗試用'except except,e:'替換'except:'行,並在下一行放置print e'。它會給你更多的信息,而不是簡單的「打印」錯誤3「' – eumiro 2010-10-19 18:06:47
似乎你喜歡樣板代碼。你有沒有想過用Java編程?好吧,開開玩笑 - 永遠不要使用'嘗試:...除了:'。如果您無法處理特定異常,請讓它通過,以便您可以看到回溯。刪除所有那些'except:print ...'行並告訴我們你得到了什麼異常。 – AndiDog 2010-10-19 18:07:48
你爲什麼連接兩次? – SilentGhost 2010-10-19 18:33:20