使用 ftplib 访问 FTP URL
- 作者: 无糖绿箭
- 来源: 51数据库
- 2022-10-21
问题描述
我在 Windows 中使用带有 ftplib 的 python 来访问 ftp5.xyz.eu 的文件夹.
I am using python in Windows with ftplib to access a folder at ftp5.xyz.eu.
文件夹是 ftp5.xyz.eu 中的文件夹 'foo bar' 中的 'baz'.所以:ftp5.xyz.eu/foo bar/baz
The folder is 'baz' in ftp5.xyz.eu in the folder 'foo bar'. So : ftp5.xyz.eu/foo bar/baz
我在 ftp5.xyz.eu 成功连接,但是当我将整个路径写入文件夹时,它给了我一个错误:
I connect successfully at ftp5.xyz.eu but when i write the whole path to the folder it gives me an error:
from ftplib import FTP
#domain name or server ip:
ftp = FTP('ftp5.xyz.eu/foo%20bar')
...
ftp.dir()
错误如下:
File "C:Usersmirel.voicuAppDataLocalProgramsPythonPython37libftplib.py", line 117, in __init__
self.connect(host)
File "C:Usersmirel.voicuAppDataLocalProgramsPythonPython37libftplib.py", line 152, in connect
source_address=self.source_address)
File "C:Usersmirel.voicuAppDataLocalProgramsPythonPython37libsocket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:Usersmirel.voicuAppDataLocalProgramsPythonPython37libsocket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
推荐答案
这个和空间无关.FTP 构造函数的第一个参数 是 host - 主机名 或 IP 地址 - 不是 URL.
This has nothing to do with the space. The first argument of FTP constructor is host – a hostname or an IP address – not an URL.
应该是这样的:
ftp = FTP('ftp5.xyz.eu')
如果您想列出 foo bar 子文件夹中的文件,请执行以下操作:
If you want to list files in foo bar subfolder, either do:
ftp.cwd('foo bar')
ftp.dir()
或
ftp.dir('foo bar')
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
