2017-10-19 67 views
-1

我想通過FTP上傳文件,我有以下代碼:無法上傳到FTP服務器在Python

def ftp_upload(localfile, remotefile): 
    fp = open(localfile, 'rb') 
    ftp.storbinary('STOR %s' % os.path.basename(localfile), 'rb', 1024) 
    fp.close() 
    print ("after upload " + localfile + " to " + remotefile) 

代碼執行與出錯誤,但沒有上傳任何文件。

+0

您是否忘記了帖子中的縮進或實際代碼中的縮進?如果是這樣,函數每次都返回None,下面的代碼不會被函數執行。 – mrCarnivore

回答

1

爲什麼

您正在使用「RB」作爲文件指針,在這裏你應該用你打開

示例代碼[Source(略有修改)

文件指針代碼不工作
def placeFile(): 
    filename = 'exampleFile.txt' 
    open_file = open(filename, 'rb') 
    ftp.storbinary('STOR '+filename, open_file) 
    ftp.quit() 
placeFile()