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
评论列表
文章目录