Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class tyFTP(ftplib.FTP_TLS):
- def __init__(self,
- host='',
- user='',
- passwd='',
- acct='',
- keyfile=None,
- certfile=None,
- timeout=60):
- ftplib.FTP_TLS.__init__(self,
- host=host,
- user=user,
- passwd=passwd,
- acct=acct,
- keyfile=keyfile,
- certfile=certfile,
- timeout=timeout)
- def connect(self, host='', port=0, timeout=-999):
- """Connect to host. Arguments are:
- - host: hostname to connect to (string, default previous host)
- - port: port to connect to (integer, default previous port)
- """
- 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
- # add this line!!!
- self.sock = ssl.wrap_socket(self.sock,
- self.keyfile,
- self.certfile,
- ssl_version=ssl.PROTOCOL_TLSv1)
- # add end
- self.file = self.sock.makefile('rb')
- self.welcome = self.getresp()
- except Exception as e:
- print(e)
- return self.welcome
- 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
- from ImplicityTLS import tyFTP
- server = tyFTP()
- server.connect(host="xxxxx", port=990)
- server.login(user="yyyy", passwd="fffff")
- server.prot_p()
- from ftplib import FTP_TLS, FTP
- import socket
- import ssl
- class IMPLICIT_FTP_TLS(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):
- '''Connect to host. Arguments are:
- - host: hostname to connect to (string, default previous host)
- - port: port to connect to (integer, default previous port)
- '''
- 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)
- self.file = self.sock.makefile('rb')
- self.welcome = self.getresp()
- except Exception as e:
- print (e)
- return self.welcome
- def ntransfercmd(self, cmd, rest=None):
- conn, size = FTP.ntransfercmd(self, cmd, rest)
- if self._prot_p:
- conn = ssl.wrap_socket(conn, self.keyfile, self.certfile)
- return conn, size
- >>> ftps = IMPLICIT_FTP_TLS()
- >>> ftps.connect(host='your.ftp.host', port=990)
- >>> ftps.login(user="your_user", passwd="your_passwd")
- >>> ftps.prot_p()
- >>> ftps.retrlines('LIST')
- import ftplib, os, sys
- import socket
- import ssl
- FTPS_OBJ = ftplib.FTP_TLS
- def conn_i_ftps(FTP_Site, Login_Name, Login_Password):
- print "Starting IMPLICIT ftp_tls..."
- ftps = tyFTP()
- print ftps.connect(host=FTP_Site, port=990, timeout=120)
- ftps.prot_p()
- ftps.login(user=Login_Name, passwd=Login_Password)
- print "Logged In"
- ftps.retrlines('LIST')
- # return ftps
- class tyFTP(FTPS_OBJ):
- def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None, timeout=60):
- FTPS_OBJ.__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)
- self.file = self.sock.makefile('rb')
- self.welcome = self.getresp()
- except Exception as e:
- print e
- return self.welcome
- def makepasv(self):
- print port #<---Show passively assigned port
- print host #<---Show the non-routable, passively assigned IP
- host, port = FTPS_OBJ.makepasv(self)
- host = socket.gethostbyname(self.host) #<---- This changes the host back to the original IP that was used for the connection
- print 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
- print host #<----Showing the original IP
- return host, port
- FTP_Site = "ftp.someserver.com"
- Login_Name = "some_name"
- Login_Password = "some_passwd"
- conn_i_ftps(FTP_Site, Login_Name, Login_Password)
- if host.split(".")[0] in (10, 192, 172):
- host = socket.gethostbyname(self.host)
- .
- .
- .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement