Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. from ftplib import FTP_TLS
  2. import socket
  3. import ssl
  4.  
  5.  
  6. class tyFTP(FTP_TLS):
  7. def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None, timeout=60):
  8. FTP_TLS.__init__(self, host, user, passwd, acct, keyfile, certfile, timeout)
  9.  
  10. def connect(self, host='', port=0, timeout=-999):
  11. if host != '':
  12. self.host = host
  13. if port > 0:
  14. self.port = port
  15. if timeout != -999:
  16. self.timeout = timeout
  17.  
  18. try:
  19. self.sock = socket.create_connection((self.host, self.port), self.timeout)
  20. self.af = self.sock.family
  21. self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ssl_version=ssl.PROTOCOL_TLSv1)
  22. self.file = self.sock.makefile('rb')
  23. self.welcome = self.getresp()
  24. except Exception as e:
  25. print e
  26. return self.welcome
  27.  
  28.  
  29. server = tyFTP()
  30. server.set_debuglevel(2)
  31. server.set_pasv(True)
  32. print server.connect(host="host", port=990, timeout=60)
  33. print server.login(user="uname", passwd="pass")
  34.  
  35. server.retrlines('LIST')
  36.  
  37. *get* '220-Microsoft FTP Servicern'
  38. *get* '<<Welcome Message>>rn'
  39. *resp* '<<Welcome Message>>'
  40. 220-<<Welcome Message>>
  41. *cmd* 'USER <<USER>>'
  42. *put* 'USER <<USER>>rn'
  43. *get* '331 Password required for <<USER>>.rn'
  44. *resp* '331 Password required for <<USER>>.'
  45. *cmd* 'PASS **********'
  46. *put* 'PASS **********rn'
  47. *get* '230-WELCOMErn'
  48. *get* '230 User logged in.rn'
  49. *resp* '230-WELCOMEn230 User logged in.'
  50. 230-WELCOME
  51. 230 User logged in.
  52. *cmd* 'TYPE A'
  53. *put* 'TYPE Arn'
  54. *get* '200 Type set to A.rn'
  55. *resp* '200 Type set to A.'
  56. *cmd* 'PASV'
  57. *put* 'PASVrn'
  58. *get* '227 Entering Passive Mode (192,168,101,20,11,184).rn'
  59. *resp* '227 Entering Passive Mode (192,168,101,20,11,184).'
  60. Traceback (most recent call last):
  61. File "C:/..../test2.py", line 35, in <module>
  62. server.retrlines('LIST')
  63. File "C:Python27libftplib.py", line 699, in retrlines
  64. conn = self.transfercmd(cmd)
  65. File "C:Python27libftplib.py", line 361, in transfercmd
  66. return self.ntransfercmd(cmd, rest)[0]
  67. File "C:Python27libftplib.py", line 674, in ntransfercmd
  68. conn, size = FTP.ntransfercmd(self, cmd, rest)
  69. File "C:Python27libftplib.py", line 327, in ntransfercmd
  70. conn = socket.create_connection((host, port), self.timeout)
  71. File "C:Python27libsocket.py", line 567, in create_connection
  72. raise error, msg
  73. 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
  74.  
  75. Process finished with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement