2017-09-28 79 views
1

我在行「ftp.retrbinary(」RETR「+ filename,localfile.write)」中收到錯誤。它沒有說我剛剛得到什麼錯誤ftplib.error_perm:500未知命令。索姆恩能幫我弄清楚這個問題嗎?在retrbinary中的FTPlib錯誤

from ftplib import FTP 

def grabfile(): 

    if not os.path.exists(dtt): 
     os.makedirs(dtt) 


    ftp = FTP('IP') 
    ftp.login(user="ftpread", passwd = 'PSW') 
    ftp.cwd("/var/log/") 
    filename = "scxmlsoap.log" 
    #localfilename = "scxmlsoap.log" 
    localfile = open(filename, "wb") 
    ftp.retrbinary("RETR" + filename, localfile.write) 
    ftp.quit() 
    localfile.close() 
    f.close() 

def main(): 
    grabfile() 

main() 
+0

它表示error_perm。它可能是一個權限錯誤,意味着你沒有正確的權限來編寫你正在寫的文件? – sissy

回答

1

只需在RETR後添加一個空格,這裏是一個更新版本。

ftp = FTP('IP') 
ftp.login(user="ftpread", passwd = 'PSW') 
ftp.cwd("/var/log/") 
filename = "scxmlsoap.log" 
#localfilename = "scxmlsoap.log" 
localfile = open(filename, "wb") 
ftp.retrbinary("RETR %s" % filename, localfile.write) # <-- a space added 
ftp.quit() 
localfile.close() 
f.close() 
+0

非常感謝,幫助。 – Nastyjoe

+0

歡迎您;) –

1

,你有'RETR'之間沒有空格和文件名意味着你發送一個命令的事實:'RETRscxmlsoap.log'。這當然不會被解釋爲您需要的'RERT'命令。

只需在它們之間加上一個空格:'RERT {}'.format(filename)