def ftp_upload(file_path): host = '' user = '' password = '' f = ftpretty(host, user, password ) f.put(file_path , '/')
def __init__(self, import_name=__package__, db=None, *args, **kwargs): """Cabu main class, acts as a WSGI interface. It overrides Flask to include the config, the Selenium WebDriver, the Database, eventually an S3 bucket and a FTP. Args: import_name (str): Same as for Flask initialization. db (Optional[object]): The database driver class. Defaults to None. Returns: object: A Flask instance plus Cabu specific attributes. """ super(Cabu, self).__init__(import_name, **kwargs) settings_path = os.environ.get('CABU_SETTINGS', 'cabu.default_settings') self.load_config(settings_path) if db: if 'DATABASE_URI' not in self.config: if db.__name__ == 'PyMongo': default_uri = 'mongodb://localhost/%s' % self.name else: raise ConfigurationException( 'Unknown database missing DATABASE_URI setting.' ) self.config['DATABASE_URI'] = os.environ.get( 'DATABASE_URI', default_uri ) mongo = db(self, config_prefix='DATABASE') with self.app_context(): self.db = mongo.db self.cookies = CookieStorage(self.db) if self.config.get('S3_BUCKET'): self.bucket = Bucket( self.config['S3_BUCKET'], self.config['S3_ACCESS_KEY'], self.config['S3_SECRET_KEY'] ) if self.config.get('FTP_HOST'): # pragma: no cover self.ftp = ftpretty( self.config['FTP_HOST'], self.config['FTP_LOGIN'], self.config['FTP_PASSWORD'] ) self.vdisplay = load_vdisplay(self.config) self.webdriver = load_driver(self.config, self.vdisplay)
def get_binary_file(self, remote_folder, remote_file_name): contents = None try: # open connection f = ftpretty(FTP_HOST, FTP_USER, FTP_PASS) # cd base folder f.cd(FTP_BASE_DIR) # download the file contents = f.get(remote_folder + "/" + remote_file_name) except: print("Unexpected error:", sys.exc_info()) finally: if f: f.close() return contents
def get_binary_file(self,remote_folder, remote_file_name): contents = None try: # open connection f = ftpretty(FTP_HOST, FTP_USER, FTP_PASS) # cd base folder f.cd(FTP_BASE_DIR) # download the file contents = f.get(remote_folder + SLASH + remote_file_name) except: print("Unexpected error:", sys.exc_info()) finally: if f: f.close() return contents
def download_file(self, remote_folder, remote_file_name, local_file_path): try: # open connection f = ftpretty(FTP_HOST, FTP_USER, FTP_PASS) # cd base folder f.cd(FTP_BASE_DIR) # download the file contents = f.get(remote_folder + SLASH + remote_file_name) my_file = open(local_file_path, 'wb') my_file.write(contents) my_file.close() except: print("Unexpected error:", sys.exc_info()) finally: if f: f.close()
def download_file(self, remote_folder, remote_file_name, local_file_path): try: # open connection f = ftpretty(FTP_HOST, FTP_USER, FTP_PASS) # cd base folder f.cd(FTP_BASE_DIR) # download the file contents = f.get(remote_folder + "/" + remote_file_name) my_file = open(local_file_path, 'wb') my_file.write(contents) my_file.close() except: print("Unexpected error:", sys.exc_info()) finally: if f: f.close()
def place_test_file_in_fpga(file_path, host_addr='192.168.43.3', remote_file_path='/home/root/Vitis-AI/dex_read'): """ File copies the file pointed to by file_path to the remote_file_path on the server pointed to by host_addr """ # Supply the credentisals f = ftpretty(host_addr, "root", "root") file = np.load(file_path) # read in the numpy file # Get a file, save it locally # f.get('someremote/file/on/server.txt', '/tmp/localcopy/server.txt') # Put a local file to a remote location # non-existent subdirectories will be created automatically f.put(file_path, remote_file_path+'/')
def connect(self): if self._alt_ftp_con is None: try: logger.debug('Connecting to ' + str(self.get_host()) + ' with user ' + str(self.get_user())) self._ftp = ftpretty(self.get_host(), self.get_user(), self.get_password(), timeout=self.get_connect_timeout()) return True except: logger.exception('Unable to connect to ftp host') self._error_msg = 'Unable to connect to ftp host' return False self._ftp = self._alt_ftp_con return True
def upload_file(self, local_file_path, remote_folder, remote_file_name): try: ret = 0 # open connection f = ftpretty(FTP_HOST, FTP_USER, FTP_PASS) # cd base folder f.cd(FTP_BASE_DIR) # put the file print("local_file_path: " + local_file_path) print("remote_folder: " + remote_folder) print("remote_file_name: " + remote_file_name) ret = f.put(local_file_path, remote_folder + "/" + remote_file_name) except: print("Unexpected error:", sys.exc_info()) finally: if f: f.close() return ret
def perform(self, *args, **kwargs): import click files_to_copy = kwargs.pop('copied_files') if len(files_to_copy) == 0: files_to_copy = kwargs.pop('jar_files') ftp_client = ftpretty(host=kwargs.pop("host"), user=kwargs.pop("user"), password=kwargs.pop("password")) put_directory = kwargs.pop('directory') click.echo("Connected to FTP Remote Host; Uploading files to %s" % put_directory) ftp_client.cd(put_directory) for copied in files_to_copy: base_file = os.path.basename(copied) ftp_client.put(copied, base_file) click.echo("Uploaded %s to %s" % (base_file, put_directory)) ftp_client.close()
def test_custom_port(self): ftpretty(None, None, None, ftp_conn=self.mock_ftp, port=2121)
def test_set_pasv(self): ftpretty(None, None, None, ftp_conn=self.mock_ftp, passive=False)
def setUp(self): self.mock_ftp = MockFTP() self.pretty = ftpretty(None, None, None, ftp_conn=self.mock_ftp)
def test_set_pasv(self): pretty = ftpretty(None, None, None, ftp_conn=self.mock_ftp, passive=False)
def __init__(self, *args, **kwargs): self.conn = ftpretty(*args, **kwargs)
import os from ftpretty import ftpretty from userbot import config host = config.get('seedbox', 'host', fallback=None) username = config.get('seedbox', 'username', fallback=None) password = config.get('seedbox', 'password', fallback=None) ftp = ftpretty(host=host, user=username, password=password) async def tree(path): files = [] ftp.cd(path) for x in ftp.list(ftp.pwd(), extra=True): if x['directory'] == 'd': inner_files = await tree(x['name']) files = files + inner_files ftp.cd('..') elif x['directory'] == '-': file_name = f"{ftp.pwd()}/{x['name']}" files.append([x['datetime'], x['size'], file_name]) return files async def get_ftp_files(): file_list = await tree('downloads/manual') files_grouped_by_date = {}
def get_ftp_connection(self): return ftpretty(FTP_HOST, FTP_USER, FTP_PASS)
def __init__(self, ip, port, username, password) -> None: self.conn = ftpretty(ip, username, password, port=port)