From f039f4c3e44d77456521013030fb3e955e7d9a61 Mon Sep 17 00:00:00 2001 From: Miha <miha.fosnaric@fe.uni-lj.si> Date: Mon, 25 Mar 2019 09:04:14 +0000 Subject: [PATCH] Merge branch 'master' of https://bitbucket.org/samop/trisurf-manager --- trisurf/Remote.py | 32 ++++++++++++++++++++++++++++++-- 1 files changed, 30 insertions(+), 2 deletions(-) diff --git a/trisurf/Remote.py b/trisurf/Remote.py index 8da08be..977b96a 100644 --- a/trisurf/Remote.py +++ b/trisurf/Remote.py @@ -1,6 +1,5 @@ import paramiko - - +import os.path class Connection: def __init__(self, hostname, port=22, username=None, password=None): @@ -70,4 +69,33 @@ sftp.mkdir(directory) sftp.close() + def mkdir_p(self,sftp, remote_directory): + """Change to this directory, recursively making new folders if needed. + Returns True if any folders were created. Recursive algorithm.""" + if remote_directory == '/': + # absolute path so change directory to root + sftp.chdir('/') + return + if remote_directory == '': + # top-level relative directory must exist + return + try: + sftp.chdir(remote_directory) # sub-directory exists + except IOError: + dirname, basename = os.path.split(remote_directory.rstrip('/')) + self.mkdir_p(sftp, dirname) # make parent directories + sftp.mkdir(basename) # sub-directory missing, so created it + sftp.chdir(basename) + return True + def send_multiple_files_in_directory(self,local_files,directory): + sftp=self.ssh.open_sftp() +# try: +# sftp.chdir(directory) # Test if remote_path exists +# except (IOError,FileNotFoundError): +# sftp.mkdir(directory) # Create remote_path +# sftp.chdir(directory) + self.mkdir_p(sftp, directory) + for f in set(local_files): + sftp.put(f, f) + sftp.close() -- Gitblit v1.9.3