utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:jarvice_cli 作者: nimbix 项目源码 文件源码
def _upload_file(sftp, local_path, remote_path):
    """Wrapper to upload a single file.

    Raises:
       paramiko.sftp.SFTPError: Internal paramiko error due to SSH connection
         or other issues.
       IOError: Local file does not exist or cannot be read; post-transfer file
         sanity checks (size, etc...) fail
       Exception: Unknown failures
    """
    # local_path_stat = os.stat(local_path)
    # if not os.path.exists(local_path):
    #     logging.error("Skipping %s. Path does not exist.")

    #     or \
    #    not stat.S_ISREG(local_path_stat.st_mode):
    #     logging.error('%s is not a regular file.' % (local_path))

    # Create remote directories if necessary
    try:
        logging.info("Uploading %s to %s" % (
            local_path,
            remote_path))
        sftp.put(local_path, remote_path)
    except paramiko.sftp.SFTPError as e:
        logging.error("SFTP Error %s" % e.message)
        raise
    except IOError as e:
        logging.error("IOError %s" % e.message)
        raise
    except Exception:
        logging.error("Failure to upload %s %s" % (local_path,
                                                   remote_path))
        raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号