示例#1
0
def connect(host: str) -> Any:
    try:
        with FTP_TLS(host) as ftp:
            ftp.login()
            ftp.dir()
            resp = ftp.quit()
    except ftplib.all_errors() as err:
        print(err)
    return resp
示例#2
0
def UpdateLocalData(Force=False):
	'''
	This will download and convert any OMNI data which is missing from 
	the local archive.
	
	'''
	ftp = FTP_TLS(Globals.ftpbase)
	ftp.login()  
	ftp.cwd(Globals.ftpdir)
		
	#let's download and read the FTP index
	status = _DownloadFTPIndex(ftp)
	if not status:
		print('Download failed; check for write permission to data folder')
		ftp.close()
		return
	ftp.close()
		
	FileNames,Addresses,UpdateDates,Res = _ParseFTP()
	n = np.size(FileNames)
	
	#check current data index
	idx = _ReadDataIndex()
	
	#now compare update dates
	if Force:
		update = np.ones(n,dtype='bool')
	else:
		update = _CompareUpdates(UpdateDates,FileNames,idx)
	use = np.where(update)[0]
	FileNames = FileNames[use]
	Addresses = Addresses[use]
	UpdateDates = UpdateDates[use]
	Res = Res[use]
	n = use.size

	if n == 0:
		print('No files to update.')
		ftp.close()
		return 
		
	for i in range(0,n):
		print('Downloading file {0} of {1}'.format(i+1,n))
		#download file
		tmp = _DownloadFTPFile(FileNames[i])
		
		print('Converting to binary')
		#convert file
		_ConvertFTPFile(tmp,FileNames[i],UpdateDates[i],Res[i])
		
		#delete text file
		_DeleteFTPFile(tmp)
		
	
	ftp.close()
	print('Done')
示例#3
0
def ftps(exit):
    try:
        f = FTP_TLS(args.hostname)
        f.login(user=p_file.get('f_user'), passwd=p_file.get('f_pass'))
        f.quit()
        print(f'OK: FTPs login successful')
        return OK
    except:
        print(f'WARNING: FTPs service was not authorized')
        return CRITICAL
示例#4
0
def ftp_to_ml(localfile, remote_file):
    (user, acct, passwd) = netrc.netrc().authenticators('ftps.b2b.ml.com')
    ftp = FTP_TLS('ftps.b2b.ml.com')
    remote_dir = 'incoming/gmigefs2'
    ftp.login(user, passwd, acct)
    ftp.prot_p()
    ftp.cwd(remote_dir)
    local_fd = open(localfile, 'r')
    ftp.storlines('STOR ' + remote_file, local_fd)
    local_fd.close()
示例#5
0
文件: ftpscan.py 项目: sodaphish/ptsh
def connectFTPS(hst, usr, pwd, prt):
    try:
        ftps = FTP_TLS(hst, usr, pwd)
        retr = ftps.retrlines('SYST')
        retr.join(ftps.retrlines('PWD'))
        retr.join(ftps.retrlines('LIST'))
        ftps.quit()
        return retr
    except Exception as e:
        return "%s" % (e)
示例#6
0
def download_file_tls(host,
                      user,
                      password,
                      local_path,
                      remote_path,
                      timeout=None):
    ftp = FTP_TLS(host=host, user=user, passwd=password, timeout=timeout)
    ftp.prot_p()
    ftp.retrbinary('RETR {}'.format(remote_path), open(local_path, 'wb').write)
    ftp.quit()
def import_to_ftp(file_name):
    with FTP_TLS("ftp.cloud.viewpoint.com") as ftps:
        ftps.login("945", "QnHS6468")
        ftps.prot_p()
        ftps.cwd(r"\imports\EM\SkyBitzMtr")
        local_path = r"C:\Users\jjacinto\OneDrive - HSI\Documents\GitHub\Skybitz_Vista"
        local_file = os.path.join(local_path, file_name)
        with open(local_file, "rb") as csv_file:
            ftps.storlines("Stor " + file_name, csv_file)
        ftps.dir()
示例#8
0
    def connect_to_ftp(self, options):
        host = options['ftp_server']
        path = options['path']
        user = options['user']
        password = options['password']

        ftp = FTP_TLS(host=host)
        ftp.login(user=user, passwd=password)
        ftp.cwd(path)

        return ftp
示例#9
0
def import_to_ftp():
    import pdb
    pdb.set_trace()
    with FTP_TLS("ftp.cloud.viewpoint.com") as ftps:
        ftps.login("945", "QnHS6468")
        ftps.prot_p()
        ftps.cwd(r"\imports\EM\SkyBitzMtr")
        local_path = r"C:\Users\jjacinto\OneDrive - HSI\Documents\GitHub\Skybitz_Vista\official_sky_bits_project\official_sky_bits_project\skybitz_2020102.csv"
        with open(local_path, "rb") as csv_file:
            ftps.storlines("Stor skybitz_2020102.csv", csv_file)
        ftps.dir()
示例#10
0
def fetch_data_via_ftp(ftp_config, local_directory):
    """ Get benchmarking data from a remote ftp server. 
    :type ftp_config: config.FTPConfigurationRepresentation
    :type local_directory: str
    """
    if ftp_config.enabled:
        # Create local directory tree if it does not exist
        create_directory_tree(local_directory)

        # Login to FTP server
        if ftp_config.use_tls:
            ftp = FTP_TLS(ftp_config.server)
            ftp.login(ftp_config.username, ftp_config.password)
            ftp.prot_p()  # Request secure data connection for file retrieval
        else:
            ftp = FTP(ftp_config.server)
            ftp.login(ftp_config.username, ftp_config.password)

        if not ftp_config.files:  # Auto-download all files in directory
            fetch_data_via_ftp_recursive(ftp=ftp,
                                         local_directory=local_directory,
                                         remote_directory=ftp_config.directory)
        else:
            ftp.cwd(ftp_config.directory)

            file_counter = 1
            file_list_total = len(ftp_config.files)

            for remote_filename in ftp_config.files:
                local_filename = remote_filename
                filepath = os.path.join(local_directory, local_filename)
                if not os.path.exists(filepath):
                    with open(filepath, "wb") as local_file:
                        try:
                            ftp.retrbinary('RETR %s' % remote_filename,
                                           local_file.write)
                            print("[Setup][FTP] ({}/{}) File downloaded: {}".
                                  format(file_counter, file_list_total,
                                         filepath))
                        except error_perm:
                            # Error downloading file. Display error message and delete local file
                            print(
                                "[Setup][FTP] ({}/{}) Error downloading file. Skipping: {}"
                                .format(file_counter, file_list_total,
                                        filepath))
                            local_file.close()
                            os.remove(filepath)
                else:
                    print(
                        "[Setup][FTP] ({}/{}) File already exists. Skipping: {}"
                        .format(file_counter, file_list_total, filepath))
                file_counter = file_counter + 1
        # Close FTP connection
        ftp.close()
示例#11
0
def read_ftp():
    with FTP_TLS(os.environ['host']) as ftps:
        ftps.login(os.environ['user'], os.environ['password'])
        ftps.prot_p()

        ftps.cwd(os.environ['dir'])
        filename = os.environ['finput']

        with BytesIO() as inpbin:
            ftps.retrbinary('RETR %s' % filename, inpbin.write)
            return inpbin.getvalue().decode('utf-8-sig')
示例#12
0
def upload_file_with_ftp_over_ssl():
    yesterday = (datetime.today() - timedelta(days=1)).date().__str__()
    for _path in Path("html").glob("*"):
        if ("2021" not in _path.name) or (yesterday in _path.name):
            local_path = "html/" + _path.name
            print("uploading..\t", local_path)
            remote_path = f"twitter_aichi_covid19/{local_path.split('/')[-1]}"
            with FTP_TLS(host=host_name, user=user_name,
                         passwd=password) as ftp:
                with open(local_path, 'rb') as f:
                    ftp.storbinary(f'STOR {remote_path}', f)
示例#13
0
 def connect(self):
     """
     Try to connect to the FTP server.
     Raise an error if something went wrong.
     """
     try:
         self.ftps = FTP_TLS()
         self.ftps.set_pasv(True)
         self.ftps.connect(self._host, self._port)
     except socket.gaierror:
         raise
示例#14
0
文件: ftp_tsl.py 项目: akil3s/ftp_tls
def cliente_ftp_conexion(servidor, nombre_usuario, password):
    #abrimos la conexion
    ftps = FTP_TLS(servidor)
    ftps.login(nombre_usuario, password)
    #ftp = ftplib.FTP(servidor, nombre_usuario, password)

    #listamos los archivos de /
    ftps.cwd("/")
    print "Archivos disponibles en %s:" % servidor
    archivos = ftps.dir()
    print archivos
    ftps.quit()
示例#15
0
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 conectaFtpPort():
    host = os.environ["HOST_FTP"]
    port = os.environ["PORT_FTP"]
    user = os.environ["USER_FTP"]
    pswd = os.environ["PSWD_FTP"]

    tp = FTP_TLS()
    tp.connect(host, ast.literal_eval(port), -999)
    tp.login(user, pswd)
    tp.prot_p()
    tp.dir()
    print(tp)
示例#17
0
def upload_file_tls(host,
                    user,
                    password,
                    local_path,
                    remote_path,
                    timeout=None):
    ftp = FTP_TLS(host=host, user=user, passwd=password, timeout=timeout)
    ftp.prot_p()
    local_file = open(local_path, 'rb')
    ftp.storbinary('STOR {}'.format(remote_path), local_file)
    local_file.close()
    ftp.quit()
示例#18
0
def ftp_connection():
    credentials = get_credentials()
    ftp = FTP_TLS()

    ftp.connect(credentials['ftp_client'], )
    ftp.login(
        credentials['user'],
        credentials['password'],
    )
    server_data = parse_server_data(ftp)

    ftp.quit()
示例#19
0
 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
示例#20
0
def upload_xml():
    ftps = FTP_TLS(cfg.BING_IP_ADDRESS)
    ftps.connect()
    ftps.login(cfg.BING_FTP_USERNAME, cfg.BING_FTP_PASSWORD)
    ftps.getwelcome()

    # Add upload code here storbinary()
    file = open('bing.txt', 'rb')
    ftps.storbinary('STOR ' + 'bing.txt', file)
    file.close()

    ftps.quit()
def get_latest_file():
    with open('filenames.json') as json_file:
        files = json.load(json_file)
    flag = 0
    ftp = FTP_TLS(host='olftp.adesa.com',
                  user='******',
                  passwd='aU)kj7Qn8')
    ftp.prot_p()
    #ftp.retrlines('LIST')
    ftp.cwd('outbound/')

    file_list = []
    ftp.retrlines('MLSD', file_list.append)
    #ftp.dir(file_list.append)
    max_value = 0
    full_max = 0
    filename = ''
    full_file = ''
    for i in file_list:
        col = i.split(';')
        col_max = int(re.search(r'\d+', col[0]).group())
        if (col_max > max_value) & ('.txt' in col[-1]):
            max_value = col_max
            filename = col[-1].replace(' ', '')
        if (col_max > full_max) & ('.txt' in col[-1]) & ('FULL' in col[-1]):
            full_max = col_max
            full_file = col[-1].replace(' ', '')

    if (filename != files['inc_file']):
        localfile = open(filename, 'wb')
        ftp.retrbinary('RETR ' + filename, localfile.write, 1024)
        localfile.close()
        print("Inc file data tranfer complete")
        flag = 1
    else:
        print("Inc already there")

    if (full_file != files['full_file']):
        localfile = open(full_file, 'wb')
        ftp.retrbinary('RETR ' + full_file, localfile.write, 1024)
        localfile.close()
        print("Full file data tranfer complete")
        flag = 1
    else:
        print("Full already there")

    if flag == 1:
        new_names = {'full_file': full_file, 'inc_file': filename}
        with open('filenames.json', 'w') as outfile:
            json.dump(new_names, outfile)

    ftp.quit()
    return filename, full_file, flag
示例#22
0
文件: api.py 项目: thejlyons/zachAPI
    def download_alpha(self, filename):
        """Download the given file."""
        domain = os.environ["FTP_DOMAIN_ALPHA"]
        user = os.environ["FTP_USERNAME_ALPHA"]
        passwd = os.environ["FTP_PASSWORD_ALPHA"]

        ftp = FTP_TLS(domain)
        ftp.login(user=user, passwd=passwd)

        self.download_file(ftp, filename)

        ftp.quit()
示例#23
0
def sftp(filename,filesource):
 try:
   filename=thename+filename
   ft = FTP_TLS(theserver)
   ft.login(userper,thepast)
   #filename="sent.txt"
   fn=open(filesource,"rb")
   ft.storbinary('STOR '+filename,fn)
   ft.quit()
   fn.close()
 except Exception as e:
   ohno = e
示例#24
0
文件: ftp.py 项目: xiongyingeng/tools
 def connect(self):
     print(f"{self.server} {self.port} {self.usrname} {self.pwd}")
     ftp = FTP_TLS()
     try:
         ftp.connect(self.server, self.port)
         ftp.login(self.usrname, self.pwd)
     except:
         raise IOError('\n FTP login failed!!!')
     else:
         print(ftp.getwelcome())
         print('\n+------- FTP connection successful!!! --------+\n')
         return ftp
def upload_file():
    if request.method == 'POST':

        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']

        # if filename is empty
        if file.filename == '':
            flash('No file selected for uploading')
            return redirect(request.url)

        # if file is available and have extension of mp4, avi, webm is saved in proect directory
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)

            # saving the video file
            file.save(filename)
            flash('File successfully uploaded')
            secure = request.form['secure']
            if secure == "FTP":

                ftp = FTP()

                ftp.connect('localhost', 21)

                status = ftp.login('testuser1', 'testuser')
                print("FTP Connected", status)

                fp = open(filename, 'rb')
                ftp.storbinary('STOR %s' % os.path.basename(filename), fp,
                               1024)
                return render_template('success.html', name=filename)

            elif secure == "FTP TLS":
                ftps = FTP_TLS('localhost')
                ftps.set_debuglevel(2)
                ftps.login('testuser1', 'testuser')

                ftps.set_pasv(False)
                ftps.prot_p()
                fp = open(filename, 'rb')
                ftps.storbinary('STOR %s' % os.path.basename(filename), fp,
                                1024)
                return render_template('success.html', name=filename)

        else:
            flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
            # return to the same page
            return redirect(request.url)
示例#26
0
文件: fur.py 项目: DraeberNiels/FUR
def _create_conn_ftps(host, username, password, path):
    """
    Create FTPS connection with ftplib and create/navigate to path
    """

    # initialise FTPS connection to host
    ftps = FTP_TLS(host)
    # insert ERDA credentials here
    ftps.login(username, password)           # login before securing control channel
    ftps.prot_p()
    # navigate to path and create dirs
    ftps = _create_dir_ftps(ftps,path)
    return ftps
示例#27
0
    def fetch_temporary_gz_file(self, temporary_gz_file_path):
        with open(temporary_gz_file_path, 'wb') as file_ftp:
            file_name = ntpath.basename(temporary_gz_file_path)

            try:
                ftp = FTP_TLS(self.ftp_host, self.ftp_username,
                              self.ftp_password)
                ftp.cwd(self.ftp_path)
                ftp.retrbinary('RETR ' + file_name, file_ftp.write)
                ftp.quit()
            except:
                Logger.file_parse(self.chain, file_name)
                self.fetch_temporary_gz_file(temporary_gz_file_path)
示例#28
0
def _ftp_connect():
    """
	FTP TLS Connection from settings
	"""
    settings = request.env['b2b.settings'].get_default_params(
        fields=['server', 'user', 'password'])
    ftps = FTP_TLS(settings['server'], settings['user'], settings['password'])
    # Set debug (if debug mode is ON)
    if request.debug:
        ftps.set_debuglevel(_debug_level)
    # Secure connection
    ftps.prot_p()
    return ftps
示例#29
0
文件: command.py 项目: Aborres/tfc
 def connect(self):
     if (self.readConfig()):
         try:
             self.ftp = FTP_TLS(self.server)
             password = self.__askPassWord()
             self.ftp.login(self.user, password)
             #self.ftp.prot_p()
             return True
         except Exception, e:
             print(color.TFC + "ftc " + color.WARNING +
                   "Unable to log in...")
             self.__writeConfig("Config", "time", 0)
             return False
示例#30
0
    def connect2box(self):
        """
        Connects to the box sync server 
        """

        ftp = FTP_TLS('ftp.box.com')

        print('logging in')
        ftp.login(user=self.user, passwd=getpass.getpass())
        # move to destination directory
        ftp.cwd(self.boxFolder)
        print('FTP: moving to folder ' + self.boxFolder + ' \n')
        self.ftp = ftp