2017-08-17 116 views
2

我正在嘗試設置FTP TLS傳輸。我有嚴格的FTP和SFTP腳本,但這是我第一次接觸到TLS。我的基本腳本:Python FTP TLS不工作

import ftplib 
import ssl 

ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1_2) 
ftps = ftplib.FTP_TLS(context=ctx) 

print (ftps.connect(myhost,21)) 
print(ftps.login(myusername,mypwd)) 
print("1") 
ftps.prot_p() 
print("2") 
print (ftps.retrlines('LIST')) 
print("3") 

錯誤:

[WinError 10054] An existing connection was forcibly closed by the remote host 

在retrlines線會出現此錯誤。它表示錯誤出現在do_handshake self._sslobj.do_handshake()的ssl.py中。

我已經驗證了與WinSCP的連接,並且協議是TLS1.2

任何想法?

回答

0

嗯,問題原來是供應商只允許從特定機器訪問。一旦我在正確的機器上嘗試了腳本,它就起作用了。