from paramiko.sftp import SFTP_PERMISSION_DENIED, SFTP_NO_SUCH_FILE, \ SFTP_FAILURE, SFTP_EOF, SFTP_CONNECTION_LOST from coco.utils import get_logger from .conf import config from .service import app_service from .connection import SSHConnection from .const import ( PERMS_ACTION_NAME_DOWNLOAD_FILE, PERMS_ACTION_NAME_UPLOAD_FILE, PERMS_ACTION_NAME_ALL, ) CURRENT_DIR = os.path.dirname(__file__) logger = get_logger(__file__) def convert_error(func): @wraps(func) def wrapper(*args, **kwargs): error = None try: response = func(*args, **kwargs) except FileNotFoundError as e: error = e response = SFTP_NO_SUCH_FILE except PermissionError as e: error = e response = SFTP_PERMISSION_DENIED except OSError as e:
# -*- coding: utf-8 -*- # import stat import threading from flask import send_file import os from coco.utils import get_logger from .base import BaseVolume logger = get_logger(__name__) class SFTPVolume(BaseVolume): def __init__(self, sftp): self.sftp = sftp self.root_name = 'Home' self._stat_cache = {} self._fd_cache = dict() self.lock = threading.Lock() super(SFTPVolume, self).__init__() def close(self): for fd in self._fd_cache.values(): fd.close() self.sftp.close() def get_volume_id(self): tran = self.sftp.get_channel().get_transport() addr = tran.getpeername()