2
的Python 3.6.1的Windows 10的x64Python的FTP無效參數
我此腳本的目標是從一個FTP站點搶一個.zip文件,然後把它變成一個本地目錄:
from ftplib import FTP
FTP_SERVER = 'ftp.name.com'
def main():
ftp_conn = FTP(FTP_SERVER)
ftp_conn.login('username','password')
get_binary_file(ftp_conn, 'file.zip', 'C:\Temp\test.zip')
ftp_conn.close()
def get_binary_file(ftp_client, file_name, dest=None):
if not dest:
dest = file_name
ftp_cmd = 'RETR {}'.format(file_name)
with open(dest,'wb') as dest_in:
ftp_client.retrbinary(
ftp_cmd,
dest_in.write
)
if __name__ == '__main__':
main()
我不斷收到一個錯誤的第三個參數(C:\ TEMP \ test.zip)無效:
Traceback (most recent call last):
File "C:/code/ftp_dl_binary_file1.py", line 32, in <module>
main()
File "C:/code/ftp_dl_binary_file1.py", line 13, in main
get_binary_file(ftp_conn, 'file.zip', 'C:\Temp\test.zip')
File "C:/code/ftp_dl_binary_file1.py", line 23, in get_binary_file
with open(dest,'wb') as dest_in:
OSError: [Errno 22] Invalid argument: 'C:\\Temp\test.zip'
是什麼樣的說法無效?
這做到了!感謝伯尼! – Matt
非常歡迎您,先生! – bernie