我在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么我不能插入 Python 列表?Why I cannot make an insert to Python list?(为什么我不能插入 Python 列表?)
在 DataFrame 的开头(最左端)插入一列Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的开头(最左端)插入一列)
Python psycopg2 没有插入到 postgresql 表中Python psycopg2 not inserting into postgresql table(Python psycopg2 没有插入到 postgresql 表中)
list extend() 索引,不仅将列表元素插入到末尾list extend() to index, inserting list elements not only to the end(list extend() 索引,不仅将列表元素插入到末尾)
如何使用 list.insert 将 Python 中的元素添加到列表How to add element in Python to the end of list using list.insert?(如何使用 list.insert 将 Python 中的元素添加到列表末尾?)
TypeError:“浮动"对象不可下标TypeError: #39;float#39; object is not subscriptable(TypeError:“浮动对象不可下标)