无法使用基于 python 的库 ftplib 连接到本地 FTP 服务器
Unable to connect to the local FTP Server using python-based library ftplib
我在我的机器上设置了本地 FTP 服务器。它设置在 127.0.0.1 和端口 21 上。当我尝试使用基于 python 的库 ftplib
访问它时,程序抛出错误。这是我 运行.
的代码
from ftplib import FTP
ftp = FTP("ftp://127.0.0.1", user = "VAIBHAV", passwd = "12345")
ftp.dir()
ftp.retrlines("LIST")
ftp.quit()
而且,这是错误。
Traceback (most recent call last):
File ".\main.py", line 5, in <module>
ftp = FTP("ftp://127.0.0.1", user = "VAIBHAV", passwd = "12345")
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\ftplib.py", line 152, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout,
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\socket.py", line 787, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
我该如何解决这个错误?
我正在使用 python 3.8.7,我的机器上有 Windows 10。
查看 the documentation,我在主机名前没有看到任何“ftp://
”,所以我认为如果您将其更改为
ftp = FTP("127.0.0.1", user="VAIBHAV", passwd="12345")
# or try "localhost" as well
ftp = FTP("localhost", user="VAIBHAV", passwd="12345")
它应该可以工作,或者至少给你一个不同的错误。
我在我的机器上设置了本地 FTP 服务器。它设置在 127.0.0.1 和端口 21 上。当我尝试使用基于 python 的库 ftplib
访问它时,程序抛出错误。这是我 运行.
from ftplib import FTP
ftp = FTP("ftp://127.0.0.1", user = "VAIBHAV", passwd = "12345")
ftp.dir()
ftp.retrlines("LIST")
ftp.quit()
而且,这是错误。
Traceback (most recent call last):
File ".\main.py", line 5, in <module>
ftp = FTP("ftp://127.0.0.1", user = "VAIBHAV", passwd = "12345")
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\ftplib.py", line 152, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout,
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\socket.py", line 787, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\VAIBHAV\AppData\Local\Programs\Python\Python38\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
我该如何解决这个错误?
我正在使用 python 3.8.7,我的机器上有 Windows 10。
查看 the documentation,我在主机名前没有看到任何“ftp://
”,所以我认为如果您将其更改为
ftp = FTP("127.0.0.1", user="VAIBHAV", passwd="12345")
# or try "localhost" as well
ftp = FTP("localhost", user="VAIBHAV", passwd="12345")
它应该可以工作,或者至少给你一个不同的错误。