gpt4 book ai didi

python - ftplib 文件选择

转载 作者:太空宇宙 更新时间:2023-11-04 06:20:49 24 4
gpt4 key购买 nike

手册说

To download a file, use ftp.retrlines('RETR ' + filename)

这是我的做法:

ftp.retrbinary('RETR media/backups/andrey.txt', open("file_to_get.txt", 'a+').write)

有人可以建议如何在“RETR”命令之后放置先前通过 raw_input 添加的文件名变量吗?使用 %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:\>

最佳答案

这可能有用

filename = 'andrey.txt'
path = "media/backups/"
ftp.cwd(path)
ftp.retrbinary("RETR " + filename ,open(filename, 'a+').write)

关于python - ftplib 文件选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12423501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com