2016-04-22 24 views
0

我需要在windows中登錄ftps服務器,附上我試圖與ftps建立連接的代碼。如何使用python在windows下從ftps服務器下載目錄

from ftplib import FTP_TLS 
ftps = FTP_TLS('my host addres',990) 
ftps.login('username','password')   
ftps.prot_p()   
ftps.retrlines('LIST') 

當我執行此代碼時,出現了套接字錯誤沒有10060.i知道我的FTP連接implicit.I很新的python.so請人幫我解決這個問題。

回答

0

這裏是我的問題的答案。在python中有一個名爲chilkat的模塊,我可以登錄到隱式ftps服務器。

import sys 
import chilkat 

ftp = chilkat.CkFtp2() 

# Any string unlocks the component for the 1st 30-days. 
success = ftp.UnlockComponent("Anything for 30-day trial") 
if (success != True): 
    print(ftp.lastErrorText()) 
    sys.exit() 

# If this example does not work, try using passive mode 
# by setting this to True. 
ftp.put_Passive(False) 
ftp.put_Hostname("ur host ip") 
ftp.put_Username("usename") 
ftp.put_Password("passowrd") 
ftp.put_Port(990) 

# We don't want AUTH SSL: 
ftp.put_AuthTls(False) 

# We want Implicit SSL: 
ftp.put_Ssl(True) 

# Connect and login to the FTP server. 
success = ftp.Connect() 
if (success != True): 
    print(ftp.lastErrorText()) 
    sys.exit() 
else: 
    # LastErrorText contains information even when 
    # successful. This allows you to visually verify 
    # that the secure connection actually occurred. 
    print(ftp.lastErrorText()) 

print("FTPS Channel Established!") 

# Do whatever you're doing to do ... 
# upload files, download files, etc... 
localFilename = "c:/temp/hamlet.xml" 
remoteFilename = "hamlet.xml"#the file name which u download from the ftps 
# Download a file. 
success = ftp.GetFile(remoteFilename,localFilename) 
if (success != True): 
    print(ftp.lastErrorText()) 

ftp.Disconnect() 
相關問題