Skip to content

Commit

Permalink
Make redssh.sftp.SFTP().put_folder() only take directories and make…
Browse files Browse the repository at this point in the history
… sure to at least try to create that initial directory.

Update CI script.
  • Loading branch information
Red-M committed Dec 29, 2019
1 parent 8cded68 commit ab258f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
38 changes: 22 additions & 16 deletions redssh/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,35 @@ def put_folder(self,local_path,remote_path):
'''
Upload an entire folder via SFTP to the remote session. Similar to ``cp -r /files/* /target``
Also retains file permissions.
Local path must be a directory to upload, if a path to a file is provided, nothing will happen.
:param local_path: The local path, on the machine where your code is running from, to upload from.
:type local_path: ``str``
:param remote_path: The remote path to upload the ``local_path`` to.
:type remote_path: ``str``
'''
if self.caller.__check_for_attr__('sftp'):
for (dirpath,dirnames,filenames) in os.walk(local_path):
for dirname in sorted(dirnames):
local_dir_path = os.path.join(dirpath,dirname)
tmp_rpath = local_dir_path[len(local_path):]
if tmp_rpath.startswith(os.path.sep):
tmp_rpath = tmp_rpath[1:]
remote_dir_path = os.path.join(remote_path,tmp_rpath)
if not dirname in self.list_dir(remote_path).readdir():
self.mkdir(remote_dir_path,os.stat(local_dir_path).st_mode)
for filename in filenames:
local_file_path = os.path.join(dirpath,filename)
remote_file_base = local_file_path[len(local_path):0-len(filename)]
if remote_file_base.startswith('/'):
remote_file_base = remote_file_base[1:]
remote_file_path = os.path.join(os.path.join(remote_path,remote_file_base),filename)
self.put_file(local_file_path,remote_file_path)
if os.path.isdir(local_path)==True:
try:
self.mkdir(remote_path,os.stat(local_path).st_mode)
except libssh2.exceptions.SFTPProtocolError:
pass
for (dirpath,dirnames,filenames) in os.walk(local_path):
for dirname in sorted(dirnames):
local_dir_path = os.path.join(dirpath,dirname)
tmp_rpath = local_dir_path[len(local_path):]
if tmp_rpath.startswith(os.path.sep):
tmp_rpath = tmp_rpath[1:]
remote_dir_path = os.path.join(remote_path,tmp_rpath)
if not dirname in self.list_dir(remote_path).readdir():
self.mkdir(remote_dir_path,os.stat(local_dir_path).st_mode)
for filename in filenames:
local_file_path = os.path.join(dirpath,filename)
remote_file_base = local_file_path[len(local_path):0-len(filename)]
if remote_file_base.startswith('/'):
remote_file_base = remote_file_base[1:]
remote_file_path = os.path.join(os.path.join(remote_path,remote_file_base),filename)
self.put_file(local_file_path,remote_file_path)

def put_file(self,local_path,remote_path):
'''
Expand Down
9 changes: 6 additions & 3 deletions tests/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
CI_SYSTEM=${1}
PYTHON_MAJOR_VERSION=${2}
PYTHON_MINOR_VERSION=${3}
if [ ! -z PYTHON_MAJOR_VERSION ] && [ ! -z PYTHON_MINOR_VERSION ]; then
PYTHON_VERSION=${PYTHON_MAJOR_VERSION}"."${PYTHON_MINOR_VERSION}
elif [ ! -z PYTHON_MAJOR_VERSION ]; then

if [ ! -z PYTHON_MAJOR_VERSION ]; then
PYTHON_VERSION=${PYTHON_MAJOR_VERSION}
fi

if [ ! -z PYTHON_MINOR_VERSION ]; then
PYTHON_VERSION=${PYTHON_VERSION}"."${PYTHON_MINOR_VERSION}
fi

apt update
apt install -y make curl wget openssh-client git openssh-server cmake libssl-dev zlib1g-dev

Expand Down

0 comments on commit ab258f8

Please sign in to comment.