手册说:
要下载文件,使用ftp.retrlines(“RETR” +文件名)
这是我做的:
ftp.retrbinary('RETR media/backups/andrey.txt', open("file_to_get.txt", 'a+').write)
能不能请别人告诉我如何把文件名可变的,以前通过添加的raw_input的“RETR”命令后? 用于%S但这不起作用,它就会像处理一个文件名的一部分。
ftp.retrbinary('RETR %s', open("file_to_get.txt", 'a+').write) %raw_input("print file name")
这产生:
c:\>python ftp_client.py
Enter host95.31.8.52
drwxrwxrwx 61 99 102 32768 Sep 14 01:39 backpl
drwxrwxrwx 19 99 102 4096 Sep 7 13:47 media
drwxrwxrwx 2 99 102 4096 Jul 2 11:15 naswebsite
Traceback (most recent call last):
File "ftp_client.py", line 12, in <module>
ftp.retrbinary('RETR %s', open("file_to_get.txt", 'a+').write) %raw_input("p
rint file name")
File "C:\Python27\lib\ftplib.py", line 399, in retrbinary
conn = self.transfercmd(cmd, rest)
File "C:\Python27\lib\ftplib.py", line 361, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Python27\lib\ftplib.py", line 330, in ntransfercmd
resp = self.sendcmd(cmd)
File "C:\Python27\lib\ftplib.py", line 244, in sendcmd
return self.getresp()
File "C:\Python27\lib\ftplib.py", line 219, in getresp
raise error_perm, resp
ftplib.error_perm: 550 Can't open %s: No such file or directory
c:\>