Access FTP URL with ftplib(使用 ftplib 访问 FTP URL)
问题描述
我在 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')
这篇关于使用 ftplib 访问 FTP URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 ftplib 访问 FTP URL
基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
