From d7e21ad16473dbc2b12f20c6ef34a09f73863912 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 07 Jan 2017 20:55:10 +0000
Subject: [PATCH] Copying all tapes to all remotes. Copy is possible to configured directory. Must fix runs

---
 trisurf/Remote.py |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/trisurf/Remote.py b/trisurf/Remote.py
index 89a00bd..977b96a 100644
--- a/trisurf/Remote.py
+++ b/trisurf/Remote.py
@@ -1,5 +1,5 @@
 import paramiko
-
+import os.path
 
 class Connection:
 	def __init__(self, hostname, port=22, username=None, password=None):
@@ -69,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