我正在尝试使用 Python 连接到 FTP,ftplib
但它显示连接成功,但每次我运行任何服务器命令时,它都会以TimeoutError
. NOOP
命令显示200 NOOP ok.
响应,但是当我尝试ftp.dir()
或任何服务器命令时,它失败并出现以下错误。
PyDev console: starting.
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
>>> import ftplib
>>> ftp = ftplib.FTP_TLS()
>>> ftp.connect(host_address, timeout=999)
'220 (vsFTPd 3.0.3)'
>>> ftp.login(username, password)
'230 Login successful.'
>>> ftp.voidcmd("NOOP")
'200 NOOP ok.'
>>> ftp.nlst()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "c:\program files\python\38\lib\ftplib.py", line 542, in nlst
self.retrlines(cmd, files.append)
File "c:\program files\python\38\lib\ftplib.py", line 451, in retrlines
with self.transfercmd(cmd) as conn, \
File "c:\program files\python\38\lib\ftplib.py", line 382, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "c:\program files\python\38\lib\ftplib.py", line 781, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
File "c:\program files\python\38\lib\ftplib.py", line 343, in ntransfercmd
conn = socket.create_connection((host, port), self.timeout,
File "c:\program files\python\38\lib\socket.py", line 808, in create_connection
raise err
File "c:\program files\python\38\lib\socket.py", line 796, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
>>> ftp.dir()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "c:\program files\python\38\lib\ftplib.py", line 558, in dir
self.retrlines(cmd, func)
File "c:\program files\python\38\lib\ftplib.py", line 451, in retrlines
with self.transfercmd(cmd) as conn, \
File "c:\program files\python\38\lib\ftplib.py", line 382, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "c:\program files\python\38\lib\ftplib.py", line 781, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
File "c:\program files\python\38\lib\ftplib.py", line 343, in ntransfercmd
conn = socket.create_connection((host, port), self.timeout,
File "c:\program files\python\38\lib\socket.py", line 808, in create_connection
raise err
File "c:\program files\python\38\lib\socket.py", line 796, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
>>> ftp.set_pasv(False)
>>> ftp.dir()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "c:\program files\python\38\lib\ftplib.py", line 558, in dir
self.retrlines(cmd, func)
File "c:\program files\python\38\lib\ftplib.py", line 450, in retrlines
resp = self.sendcmd('TYPE A')
File "c:\program files\python\38\lib\ftplib.py", line 275, in sendcmd
return self.getresp()
File "c:\program files\python\38\lib\ftplib.py", line 238, in getresp
resp = self.getmultiline()
File "c:\program files\python\38\lib\ftplib.py", line 224, in getmultiline
line = self.getline()
File "c:\program files\python\38\lib\ftplib.py", line 206, in getline
line = self.file.readline(self.maxline + 1)
File "c:\program files\python\38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "c:\program files\python\38\lib\ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "c:\program files\python\38\lib\ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2607)
我也试过了ftplib.FTP()
,显示同样的错误。
ftplib
与其他非 SSL 服务器一起工作正常。- 远程服务器正在运行
Ubuntu 18.04.4 LTS
。vsftpd
FTP
用户是用vestacp
.- 我通过更改
/etc/passwd
文件更改了用户的家庭住址。 - 一切正常,
FileZilla
没有来自同一本地服务器的任何延迟。
这是vestacp
vsftpd
配置:
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_umask=022
anon_upload_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
dual_log_enable=YES
chroot_local_user=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=NO
tcp_wrappers=YES
force_dot_files=YES
ascii_upload_enable=YES
ascii_download_enable=YES
allow_writeable_chroot=YES
seccomp_sandbox=NO
pasv_enable=YES
pasv_promiscuous=YES
pasv_min_port=12000
pasv_max_port=12100
max_per_ip=10
max_clients=100
use_localtime=YES
utf8_filesystem=YES
#ssl
ssl_enable=YES
allow_anon_ssl=NO
require_ssl_reuse=NO
ssl_ciphers=HIGH
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
force_local_data_ssl=NO
force_local_logins_ssl=NO
rsa_cert_file=/usr/local/vesta/ssl/certificate.crt
rsa_private_key_file=/usr/local/vesta/ssl/certificate.key