我正在尝试建立到FTP服务器的FTPS (或FTP)连接。这是通过Visual Studio代码在Python 3.8.5 32位上完成的。
代码如下:
import ftplib
session = ftplib.FTP_TLS('server address')
#session.connect ('server address', 991)
session.login(user='username',passwd='password')
#session.prot_p()
session.set_pasv(True)
session.cwd("files")
print(session.pwd())
filename = "ftpTest.txt"
my_file = open('filepath\\ftpTest.txt', 'wb') # Open a local file to store the downloaded file
session.retrbinary('RETR ' + filename, my_file.write, 1024)
session.quit()我可以获得session.pwd (它显示/files),但在大约22秒内第11行(session.retrbinary)的连接超时,出现以下错误:
Exception has occurred: 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我曾尝试在Python ftplib timing out之后将session.set_pasv设置为True和False。将其设置为True将引发TimeoutError,将其设置为False将在第11行引发以下错误:
Exception has occurred: error_perm
500 Illegal PORT command并且还尝试在Python SSL FTP connection timing out之后设置不同的端口(991),并且它在第3行引发超时错误。
在不使用TLS的情况下使用FTP时,第4行(session.login)出现以下错误:
Exception has occurred: error_perm
530 Non-anonymous sessions must use encryption.关闭我的McAfee LiveSafe防火墙也没有帮助。Btw文件传输工程与Filezilla,能够自由传输。
发布于 2020-08-12 10:48:59
设置安全数据连接并将会话af更改为INET6似乎对我很有效。这是一位同事向我提出的建议,至于为什么它会起作用,我无法理解。如果任何人能提供适当的解释,请这样做。
代码:
session.login(user='username',passwd='password')
session.prot_p()
session.af = socket.AF_INET6https://stackoverflow.com/questions/63277885
复制相似问题