問題描述
我在 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模板網!