def get_session_ftps(host, login=None, password=None, port=21, auth=False, protocol=True): """ Creates connection with FTPS server :param host: host of FTPS server :param login: user's name :param password: password for user :param port: port of FTPS server :param auth: if it is true sets up secure control connection by using TLS/SSL :param protocol: if it is true sets up secure data connection else sets up clear text data connection :return: FTPConnector :type host: str :type login: str :type password: str :type port: int :type auth: bool :type protocol: bool :rtype: FTPConnector """ try: ftp = FTP_TLS() ftp.connect(host, port) ftp.login(login, password) if protocol: ftp.prot_p() else: ftp.prot_c() if auth: ftp.auth() return FTPConnector(ftp) except error_perm, exp: raise FTPConnectorError( exp.message )
def getfilelist(server, port, user, password, db): sqliteconnection = sqlite3.connect(db) sqlitecursor = sqliteconnection.cursor() sqlitecursor.execute('''CREATE TABLE IF NOT EXISTS files (date int, name text, CONSTRAINT 'id_UNIQUE' UNIQUE ('name'))''') sqliteconnection.commit() ftpsconnection = FTP_TLS() ftpsconnection.connect(server, port) ftpsconnection.auth() ftpsconnection.prot_p() ftpsconnection.login(user, password) ftpsconnection.prot_p() rootfiles = ftpsconnection.nlst() for i in range(0,5): episodes = ftpsconnection.nlst(rootfiles[i]) for episode in episodes: sqlitecursor.execute('''INSERT OR IGNORE INTO files VALUES ("%(date)d", "%(folder)s")''' % {'date': time.time(), 'folder': ("/" + rootfiles[i] + "/" + episode) } ) sqliteconnection.commit() sqliteconnection.close() ftpsconnection.quit() ftpsconnection.close()
def ftpDownload(filename, system): from ftplib import FTP_TLS import os ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_filename = filename with open(local_filename, 'wb') as f: def callback(data): f.write(data) ftps.retrbinary('RETR %s' % filename, callback) f.close() file_extension = str(filename.split('.')[1]) if file_extension == '7z': status = decompressit(local_filename, system) if status: print "file %s hash been downloaded." % local_filename return True
def ftp_connection(): ftp_conn = None try: logger = get_logger() logger.info("Creating object FTP_TLS()") ftp_conn = FTP_TLS() logger.info("Trying to connect to FTP(%s, %d)", FTP_HOST_NAME, FTP_PORT_NUMBER) ftp_conn.connect(FTP_HOST_NAME, FTP_PORT_NUMBER) ftp_conn.auth() logger.info("auth() 0k") ftp_conn.prot_p() logger.info("prot_p() 0k") logger.info("Trying with FTP_USER_NAME = %s", FTP_USER_NAME) ftp_conn.login(user=FTP_USER_NAME, passwd=FTP_ACCESS_KEY) ftp_conn.set_debuglevel(2) logger.info('Connected') except Exception as e: logger.error('Not connected %s', e) return ftp_conn
def _connect(server: str): global _connection_cache if server not in _connection_cache: if server == 'in_server': logger.debug(f'Connection to "in_server" requested') conn_specs = config().ftp.in_server elif server == 'out_server': logger.debug(f'Connection to "out_server" requested') conn_specs = config().ftp.out_server else: raise ValueError(f'Unknown server "{server}"') logger.debug(f'conn specs = {conn_specs}') if conn_specs.secure: ftp = FTP_TLS(conn_specs.host) ftp.auth() else: ftp = FTP(conn_specs.host) # ftp.connect(conn_specs.host, conn_specs.port) logger.debug(f'Connected to "{server}". Logging in...') ftp.login(conn_specs.username, conn_specs.password) logger.debug(f'Established connection to "{server}". Saving to cache') _connection_cache[server] = ftp return ftp else: ftp = _connection_cache[server] ftp.cwd('/') logger.debug(f'Recycling connection to "{server}"') return ftp
def ftpconnect(host, port, username, password): from ftplib import FTP_TLS ftps = FTP_TLS(timeout=100) ftps.connect("135.32.1.36", 2121) ftps.auth() ftps.prot_p() ftps.login('ftpuser', 'ftpoptr') return ftp
def start_ftpes_connection(timeout=30): ftps = FTP_TLS(timeout=timeout) ftps.connect(SETTINGS['exporters.plan2learn.host'], 21) ftps.auth() ftps.prot_p() ftps.login(SETTINGS['exporters.plan2learn.user'], SETTINGS['exporters.plan2learn.password']) return ftps
def ftpUpload(filename): from ftplib import FTP_TLS import os ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_file = open(filename, 'rb') ftps.storbinary('STOR ' + filename, local_file)
def ftpUpload(filename): from ftplib import FTP_TLS import os ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_file = open(filename, 'rb') ftps.storbinary('STOR '+filename, local_file)
def openFtpConnection(self, host="localhost", port=21, login="******", password=None, timeout=600, isSecured=False): self.isSecured = isSecured if (isSecured == True): _ftpConnection = FTP_TLS(timeout=timeout) _ftpConnection.connect(host, port) _ftpConnection.auth() _ftpConnection.prot_p() else: _ftpConnection = self.FTP(timeout=timeout) _ftpConnection.connect(host, port) _ftpConnection.login(login, password) self.ftpConnection = _ftpConnection
def ftpDownload(filename): from ftplib import FTP_TLS import os ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_filename = filename with open(local_filename, 'wb') as f: def callback(data): f.write(data) ftps.retrbinary('RETR %s' % filename, callback)
def FTPconnect(self): #initial FTP object and login the HCA FTP server try: ftp = FTP_TLS() ftp.set_pasv(True,self.host) ftp.ssl_version = ssl.PROTOCOL_TLSv1 ftp.connect(host=self.host,port=21) ftp.set_debuglevel(2) ftp.auth() ftp.login(self.user,self.password) ftp.prot_p() print (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())+' FTP login successful') return ftp except Exception as e: self.sns.informError() print (e)
def conn(self): """ Connects to ftp or sftp based on the protocol """ try: if self.port == 22: ftp_conn = FTP_TLS(self.host) ftp_conn.login(self.user, self.password) ftp_conn.auth() ftp_conn.prot_p() else: ftp_conn = FTP(self.host) ftp_conn.login(self.user, self.password) self.con = ftp_conn except Exception as e: raise e
def Push( FtpServer, Username, Password, uploadlist = FilesToPut, port = 21): print >> sys.stderr, "Login to %s:%s using %s:%s"%(FtpServer, port, Username, 'xxx') ftp = FTP() ftps = FTP_TLS() ftps.connect(FtpServer,Port) ftps.auth() ftps.login(Username, Password) # login anonymously before securing control channel ftps.prot_p() ftp.set_pasv(False) for f in uploadlist: #print "uploading %s"%f fp = open( f, 'rb') os.path.basename(f) print f ftp.storbinary("STOR,%sx " %(os.path.basename(f),fp)) #ftp.storbinary('STOR, %s',fp %(basename(f)) ) # send the file ftp.quit()
def login(self,debug=2,set_pasv=True): _old_makepasv = FTP_TLS.makepasv def _new_makepasv(self): host, port = _old_makepasv(self) host = self.sock.getpeername()[0] return host, port FTP_TLS.makepasv = _new_makepasv ftps = FTP_TLS(self.host) ftps.set_debuglevel(debug) ftps.auth() ftps.login(self.user,self.pwd) ftps.makepasv() ftps.sendcmd('pbsz 0') ftps.set_pasv(set_pasv) ftps.prot_p() print("hello ") ftps.getwelcome() return ftps
def getfiles(server, port, user, password, db): sqliteconnection = sqlite3.connect(db) sqlitecursor = sqliteconnection.cursor() sqlitecursor.execute('''CREATE TABLE IF NOT EXISTS latest (date int, CONSTRAINT 'id_UNIQUE' UNIQUE ('date'))''') sqliteconnection.commit() sqlitecursor.execute('''SELECT date FROM files WHERE date = (SELECT MAX(date) FROM files) LIMIT 1''') latestfile = sqlitecursor.fetchone() sqlitecursor.execute('''SELECT date FROM latest WHERE date = (SELECT MAX(date) FROM latest) LIMIT 1''') latestfetch = sqlitecursor.fetchone() if latestfetch is None: latestfetch = 0 if latestfetch < latestfile: ftpsconnection = FTP_TLS() ftpsconnection.connect(server, port) ftpsconnection.auth() ftpsconnection.prot_p() ftpsconnection.login(user, password) ftpsconnection.prot_p() sqlitecursor.execute('''SELECT name FROM files WHERE date > %d''' % latestfetch) filestofetch = sqlitecursor.fetchall() for currfile in filestofetch: ftpsconnection.cwd(currfile[0]) filenames = ftpsconnection.nlst() for filename in filenames: print 'Now saving /mnt/folder' + currfile[0] + '/' + filename localfile = open('/mnt/folder' + currfile + '/' + filename, 'wb') ftpsconnection.retrbinary('RETR ' + filename, localfile.write) localfile.close() sqliteconnection.execute('''INSERT OR IGNORE INTO latest VALUES (%d)''' % time.time()) sqliteconnection.commit() sqliteconnection.close() ftpsconnection.quit() ftpsconnection.close()
def ftpUpload(filename, system): from ftplib import FTP_TLS import os if os.path.isfile(filename): zipFilename = compressit(filename, system) ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_file = open(zipFilename, 'rb') ftps.storbinary('STOR ' + zipFilename, local_file) print "file %s has been uploaded." % zipFilename return True
def ftpUpload(filename, system): from ftplib import FTP_TLS import os if os.path.isfile(filename): zipFilename = compressit(filename, system) ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_file = open(zipFilename, 'rb') ftps.storbinary('STOR '+zipFilename, local_file) print "file %s has been uploaded." % zipFilename return True
def mainframe_connect(host, user='******', password='******'): ''' Creates ftp object, opens a connection to mainframe, login and secures de connection. Returns server output. Parameters: - host - server host or IP. - user - mainframe user name. If not given, 'anonymous' is used. - password - mainframe password. If not given, 'anonymous@' is used. ''' global rfftp output_msg = "" if __check_ftp_tls_status(True): rfftp = FTP_TLS(host) output_msg = rfftp.set_debuglevel(MAX_DEBUG_OUTPUT) rfftp.auth() output_msg = rfftp.login( user, password) # login before securing control channel print("Response login: "******"Response prot_p: " + output_msg) return
def get_session_ftps(host, login=None, password=None, port=21, auth=False, protocol=True): """ Creates connection with FTPS server :param host: host of FTPS server :param login: user's name :param password: password for user :param port: port of FTPS server :param auth: if it is true sets up secure control connection by using TLS/SSL :param protocol: if it is true sets up secure data connection else sets up clear text data connection :return: FTPConnector :type host: str :type login: str :type password: str :type port: int :type auth: bool :type protocol: bool :rtype: FTPConnector """ try: ftp = FTP_TLS() ftp.connect(host, port) ftp.login(login, password) if protocol: ftp.prot_p() else: ftp.prot_c() if auth: ftp.auth() return FTPConnector(ftp) except error_perm, exp: raise FTPConnectorError(exp.message)
def make_msg(self, args): # make connection conn = None if args.ssl or args.starttls: conn = FTP_TLS() conn.ssl_version = PROTOCOL_TLSv1 else: conn = FTP() if args.verbose: conn.set_debuglevel(1) conn.connect(args.host, args.port, args.timeout) if args.starttls: conn.auth() conn.prot_p() conn.login(args.user, args.password) self.conn = conn return args.message
def ftpDownload(filename, system): from ftplib import FTP_TLS import os ftps = FTP_TLS() ftps.connect('pwcrack.init6.me', '21') ftps.auth() ftps.login('DC214', 'passwordcrackingcontest') ftps.prot_p() ftps.set_pasv(True) local_filename = filename with open(local_filename, 'wb') as f: def callback(data): print "Downloading %s ..." % filename f.write(data) ftps.retrbinary('RETR %s' % filename, callback) f.close() file_extension = str(filename.rsplit('.')[2]) if file_extension == '7z': status = decompressit(local_filename, system) if status: print "file %s has been downloaded." % local_filename
createEmptyDirectory = True if opt == "-l": detectLink = True if ':' in args[0]: host, port = args[0].split(':') else: host, port = args[0], "21" #convert port as int port = int(port) if enableSSL: if port == 21: client = FTP_TLS(host) client.auth() client.prot_p() else: client = FTP_TLS_EXPLICIT() client.connect(host, port) client.prot_p() else: client = FTP() print client.connect(host, int(port)) print client.login(username, password) #log client.login(username, password) Dumper(client, createEmptyDirectory, filter, detectLink).do(targetDir) client.quit()
print("Warning: no imgdir (-i parameter) specified, you should copy by hand photos listed in {} to {}/photos/".format(args.photofile,args.name)) else: for dp, df, fn in os.walk(args.imgdir): for f in fn: copyfile('{}/{}'.format(dp,f),'{}/photos/{}'.format(dirn,f)) open(dirn+"/data.ini","w").write("title={} {}\n".format(os.path.basename(args.gpxfile)[:-4]," ".join(args.desc))) plt.savefig(dirn+"/profilo.png",transparent=True) with open(dirn+"/index.html","w") as indexf: indexf.write(page.render(inmoto=in_moto,insosta=in_sosta,totale=totale,qminima=qminima,qmassima=qmassima,distanza=distanza,uphill=uphill,downhill=downhill,dislivello=dislivello,fgpx=os.path.basename(args.gpxfile),trackname=" ".join(args.desc),data=data,tipo=tipo, minzoom=minzoom-1,maxzoom=min(19,minzoom+3),photofile=args.photofile)) if to_ftp: print("Uploading to ftp:") if q.scheme == 'ftps': f = FTP_TLS(q.hostname) #f.set_debuglevel(2) f.auth() else: f = FTP(q.hostname) f.login(q.username,q.password) if q.scheme == 'ftps': f.prot_p() put_to_ftp(f,dirn,q.path) if args.show: Thread(target=webserver,args=(dirn,)).start() browser() else: print "Error creating {}/: directory exists".format(dirn)
class Ftps_client: ##初始化的时候会把登录参数赋值初始化 def __init__(self, host, user, pwd, port=21): self.host = host self.port = port self.user = user self.pwd = pwd self.Ftp = None #self._old_makepasv=FTP_TLS.makepasv ## ftp 登录项 含有闭包项 def login(self, debug=2, set_pasv=True): _old_makepasv = FTP_TLS.makepasv def _new_makepasv(self): host, port = _old_makepasv(self) host = self.sock.getpeername()[0] return host, port FTP_TLS.makepasv = _new_makepasv self.Ftp = FTP_TLS(self.host) self.Ftp.set_debuglevel(debug) self.Ftp.auth() self.Ftp.login(self.user, self.pwd) self.Ftp.makepasv() self.Ftp.sendcmd('pbsz 0') self.Ftp.set_pasv(set_pasv) self.Ftp.prot_p() print("您好 您已经登录 ftp: %s 服务器" % self.host) self.Ftp.getwelcome() return self.Ftp #显示 目录下的 文件列表 def ftplistDir(self, ftps, sever_path): self.Ftp.cwd("/") #首先切换得到根目录下,否则会出现问题 self.Ftp.cwd(sever_path) files = ftps.nlst() for f in files: print(f) # 下载服务器文件 def ftpDownloadSeverFile(self, sever_path, sever_file, new_localfile, buffersize=1024): self.Ftp.cwd("/") self.Ftp.cwd(sever_path) with open(new_localfile, 'wb') as download_file: self.Ftp.retrbinary('RETR %s' % sever_file, download_file.write, buffersize) ##上传文件 需要注意 上传文件的 new_severfile 只能是文件名,不能包含带目录 的 文件全路径 def ftpUploadLocalFile(self, local_filepath, sever_path, new_severfile, buffersize=1024): self.Ftp.cwd("/") self.Ftp.cwd(sever_path) with open(local_filepath, 'rb') as upload_file: self.Ftp.storbinary('STOR ' + new_severfile, upload_file, buffersize)
from ftplib import FTP_TLS import os ftps = FTP_TLS(timeout=100) ftps.set_debuglevel(1) ftps.connect("192.168.1.35", 21) ftps.auth() ftps.prot_p() ftps.login('pan', '1') print(ftps.getwelcome()) print(ftps.pwd()) ftps.dir() # 下载文件 os.chdir(r'D:\Desktop\FTP_TLS\FTP\00临时存储') ftps.cwd('/') ftps.nlst() # 获取目录下的文件 filename = 'vsftpd.key' file_handle = open(filename, "wb").write ftps.retrbinary('RETR %s' % os.path.basename(filename), file_handle, blocksize=1024) # 下载ftp文件 # 上传到服务器 bufsize = 1024 localpath = 'D:\\Desktop\\FTP_TLS\FTP\\00临时存储\\test.txt' remotepath = '/test.txt' fp = open(localpath, 'rb') ftps.storbinary('STOR ' + remotepath, fp, bufsize) # 打印证书 print(ftps.context) print(ftps.certfile)
from ftplib import FTP_TLS from ftplib import FTP import os import time import ipaddress import getpass input_server = input("Enter the IP of the server you'd like to connect to:") login_name = input("Enter the username:"******"Enter the password:"******"""Enter the full path to the file including file extension of the file you'd like to upload. Example:\"C:\\Users\\Andreas Stenberg\\Desktop\\FTP-skript.py\"n:""") file = open(file_choice, "rb") try:#Frågar efter server-IP och användarnamn och lösenord ftp.auth() ftp.login(login_name, login_pwd) print(ftp.getwelcome()) ftp.prot_p() ftp.mlsd() ftp.storbinary("STOR {}".format(file_choice), file) time.sleep(5) ftp.quit() file.close() except: ftp.quit()