如何使用python连接到ftps服务器[使用端口990](不是ftp),甚至无法成功连接

问题描述 投票:-1回答:1

下面是代码。运行FTPS filezilla服务器的Azure及其Windows机器上的ftps服务器。要求是连接到ftps服务器并上传文件。FTPS连接失败。任何人都可以帮助解决这个问题。

from ftplib import FTP_TLS

ftpss = ftplib.FTP_TLS(host='11.22.333.44', user='xx', passwd='yyy',timeout=80) 
ftpss = login()
ftpss.ccc()
ftpss.prot_p()```


** Error getting as below **
*Traceback (most recent call last):
  File "C:\Users\krst\scripts\Item_master_dump_to_ftp\epc_audit\test_ftps.py", line 69, in <module>
    ftpss = ftplib.FTP_TLS(host='11.22.333.44', user='abc', passwd='xzy',timeout=80)
  File "C:\Users\gyn\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 728, in __init__
    FTP.__init__(self, host, user, passwd, acct, timeout, source_address)
  File "C:\Users\gyn\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 117, in __init__
    self.connect(host)
  File "C:\Users\gyn\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 152, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout,
  File "C:\Users\gyn\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 808, in create_connection
    raise err
  File "C:\Users\gyn\AppData\Local\Programs\Python\Python38-32\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*

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

i'm able to telnet the ftps server ip and port(990).Able to connect the ftps server and see folders using winscp. using winscp tool the File protocol is chosen as "FTP" and encryption as "TLS/SSL Implicit encryption" 
python-3.x ssl tls1.2 ftps
1个回答
0
投票

如用户DeepSpace所指出的,默认情况下FTP_TLS使用端口21。但是,如果在初始化对象时未提供任何host信息,则可以稍后使用connect指定它:

import ftplib
ftps = ftplib.FTP_TLS()
ftps.connect(host="<ip-address here>", port=<portnumber here as integer>)
ftps.auth() # This will set up the TLS/SSL-session before we send login-info.
ftps.login(user="MyUsername", passwd="MyPassword123")

# If ftps.login fails, try pass the login-info manually:
ftps.sendcmd("USER MyUsername")
ftps.sendcmd("PASS MyPassword123")
© www.soinside.com 2019 - 2024. All rights reserved.