def _sftp_copy( self, host=None, port=None, credential=None, localfo=None, remotepath=None, copy=None, hostkey=None, cwd=None ): assert copy == "put" or copy == "get" status = False logger.debug("SFTPCopyThread {0} {1} {2}".format(localfo.name, copy, remotepath)) ssh = None sftp = None try: ssh = pool_manager.borrow(host, port, credential) sftp = ssh.open_sftp() if copy == "put": sftp.putfo(localfo, remotepath, callback=None, confirm=True) elif copy == "get": sftp.getfo(remotepath, localfo, callback=None) status = True except IOError as e: logger.exception("Exception in _sftp_copy") if e.errno == FILE_NOT_FOUND_ERR: raise FileNotFoundError(remotepath) except Exception: logger.exception("Exception in _sftp_copy") finally: if ssh is not None: if sftp is not None: sftp.close() pool_manager.give_back(ssh, host, port, credential) return status
def set_remote_uri_times(self, uri, atime, mtime): scheme, parts = uriparse(uri) remotepath = parts.path ssh = None try: ssh = pool_manager.borrow(parts.hostname, parts.port, self.cred.credential) sftp = ssh.open_sftp() sftp.utime(remotepath, (atime, mtime)) except Exception: logger.exception("Exception while setting times for '%s'", uri) raise finally: if ssh is not None: sftp.close() pool_manager.give_back(ssh, parts.hostname, parts.port, self.cred.credential)
def remote_uri_stat(self, uri): scheme, parts = uriparse(uri) remotepath = parts.path ssh = None try: ssh = pool_manager.borrow(parts.hostname, parts.port, self.cred.credential) sftp = ssh.open_sftp() stat = sftp.stat(remotepath) return {"atime": stat.st_atime, "mtime": stat.st_mtime} except Exception: logger.exception("Exception while stating '%s'", uri) raise finally: if ssh is not None: sftp.close() pool_manager.give_back(ssh, parts.hostname, parts.port, self.cred.credential)
def remote_uri_stat(self, uri): scheme, parts = uriparse(uri) remotepath = parts.path ssh = None try: ssh = pool_manager.borrow(parts.hostname, parts.port, self.cred.credential) sftp = ssh.open_sftp() stat = sftp.stat(remotepath) return {'atime': stat.st_atime, 'mtime': stat.st_mtime} except Exception: logger.exception("Exception while stating '%s'", uri) raise finally: if ssh is not None: sftp.close() pool_manager.give_back(ssh, parts.hostname, parts.port, self.cred.credential)
def _sftp_copy(self, host=None, port=None, credential=None, localfo=None, remotepath=None, copy=None, hostkey=None, cwd=None): assert copy == 'put' or copy == 'get' status = False logger.debug('SFTPCopyThread {0} {1} {2}'.format( localfo.name, copy, remotepath)) ssh = None sftp = None try: ssh = pool_manager.borrow(host, port, credential) sftp = ssh.open_sftp() if copy == 'put': sftp.putfo(localfo, remotepath, callback=None, confirm=True) elif copy == 'get': sftp.getfo(remotepath, localfo, callback=None) status = True except IOError as e: logger.exception("Exception in _sftp_copy") if e.errno == FILE_NOT_FOUND_ERR: raise FileNotFoundError(remotepath) except Exception: logger.exception("Exception in _sftp_copy") finally: if ssh is not None: if sftp is not None: sftp.close() pool_manager.give_back(ssh, host, port, credential) return status