如何使用Windows中的python从ftps服务器下载目录

时间:2016-04-22 09:49:55

标签: python tcp ftps

我需要在Windows中登录ftps服务器,附上我试图与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连接是隐式的。我是python的新手。所以请任何人帮我解决这个问题。

1 个答案:

答案 0 :(得分: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()
相关问题