def exists(self): if self._matched_address: with self.sftpc() as sftpc: return sftpc.exists(self.remote_path) if sftpc.exists(self.remote_path): return sftpc.isfile(self.remote_path) return False else: raise SFTPFileException( "The file cannot be parsed as an SFTP path in form 'host:port/path/to/file': %s" % self.local_file())
def download(self, make_dest_dirs=True): with self.sftpc() as sftpc: if self.exists(): # if the destination path does not exist if make_dest_dirs: os.makedirs(os.path.dirname(self.local_path), exist_ok=True) sftpc.get(remotepath=self.remote_path, localpath=self.local_path, preserve_mtime=True) else: raise SFTPFileException( "The file does not seem to exist remotely: %s" % self.file())
def download(self, make_dest_dirs=True): with self.connection_pool.item() as sftpc: if self.exists(): # if the destination path does not exist if make_dest_dirs: os.makedirs(os.path.dirname(self.local_path), exist_ok=True) sftpc.get( remotepath=self.remote_path, localpath=self.local_path, preserve_mtime=True, ) os_sync() # ensure flush to disk else: raise SFTPFileException( "The file does not seem to exist remotely: %s" % self.local_file() )