Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ftplib import FTP_TLS
- import socket
- import ssl
- class tyFTP(FTP_TLS):
- def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None, timeout=60):
- FTP_TLS.__init__(self, host, user, passwd, acct, keyfile, certfile, timeout)
- def connect(self, host='', port=0, timeout=-999):
- if host != '':
- self.host = host
- if port > 0:
- self.port = port
- if timeout != -999:
- self.timeout = timeout
- try:
- self.sock = socket.create_connection((self.host, self.port), self.timeout)
- self.af = self.sock.family
- self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ssl_version=ssl.PROTOCOL_TLSv1)
- self.file = self.sock.makefile('rb')
- self.welcome = self.getresp()
- except Exception as e:
- print e
- return self.welcome
- server = tyFTP()
- server.set_debuglevel(2)
- server.set_pasv(True)
- print server.connect(host="host", port=990, timeout=60)
- print server.login(user="uname", passwd="pass")
- server.retrlines('LIST')
- *get* '220-Microsoft FTP Servicern'
- *get* '<<Welcome Message>>rn'
- *resp* '<<Welcome Message>>'
- 220-<<Welcome Message>>
- *cmd* 'USER <<USER>>'
- *put* 'USER <<USER>>rn'
- *get* '331 Password required for <<USER>>.rn'
- *resp* '331 Password required for <<USER>>.'
- *cmd* 'PASS **********'
- *put* 'PASS **********rn'
- *get* '230-WELCOMErn'
- *get* '230 User logged in.rn'
- *resp* '230-WELCOMEn230 User logged in.'
- 230-WELCOME
- 230 User logged in.
- *cmd* 'TYPE A'
- *put* 'TYPE Arn'
- *get* '200 Type set to A.rn'
- *resp* '200 Type set to A.'
- *cmd* 'PASV'
- *put* 'PASVrn'
- *get* '227 Entering Passive Mode (192,168,101,20,11,184).rn'
- *resp* '227 Entering Passive Mode (192,168,101,20,11,184).'
- Traceback (most recent call last):
- File "C:/..../test2.py", line 35, in <module>
- server.retrlines('LIST')
- File "C:Python27libftplib.py", line 699, in retrlines
- conn = self.transfercmd(cmd)
- File "C:Python27libftplib.py", line 361, in transfercmd
- return self.ntransfercmd(cmd, rest)[0]
- File "C:Python27libftplib.py", line 674, in ntransfercmd
- conn, size = FTP.ntransfercmd(self, cmd, rest)
- File "C:Python27libftplib.py", line 327, in ntransfercmd
- conn = socket.create_connection((host, port), self.timeout)
- File "C:Python27libsocket.py", line 567, in create_connection
- raise error, msg
- socket.error: [Errno 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
- Process finished with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement