2014-01-30 34 views
0

我正嘗試下載並上傳到FTP服務器。下載工作得很好,但上載吐出這個錯誤:ftp.storbinary與ftp.retrbinary不一樣嗎?

錯誤:AttributeError的(「‘功能’對象有沒有屬性‘讀’」)

def download_handle(block): 
    global sizeWritten 
    dFile.write(block) 
    os.system('CLS') 
    sizeWritten += len(block) 
    percentComplete = sizeWritten/totalSize 
    percentComplete = round((percentComplete*100),1) 

    print (percentComplete, "% complete") 

try: 
    dFile = open('filename', "wb") 
    print("DL File opened") 
    ftp.retrbinary("RETR " + filename, download_handle) 
    print("Download Completed") 
    dFile.close() 
except Exception as e: 
    print("Error:", repr(e)) 

def upload_handle(block): 
    global sizeWritten 
    upFile.write(block) 
    os.system('CLS') 
    percentComplete = sizeWritten/totalSize 
    percentComplete = round((percentComplete*100),1) 

    print (percentComplete, "% complete") 


try: 
    upFile = open('filename', "rb") 
    print("UL File opened") 
    ftp.storbinary("STOR " + filename, upload_handle) 
    print ("Upload completed") 
    upFile.close() 
except Exception as e: 
    print("Error:", repr(e)) 
+0

你永遠不會分配'download_handle',或者就此而言,'upload_handle'。請發佈*工作*代碼。 – kindall

回答

0

注意,retrbinary方法需要你傳遞一個將被用來寫入數據的函數。通常你應該通過dFile.write。我不知道download_handle是因爲你沒有定義它,但它可能不是正確的方法。同樣,對於storbinary,您想通過upFile.read

+0

增加了函數調用,抱歉延遲 – user3254903

相關問題