Commit 1c37335e authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added recursive copy of files and dirs.

parent fea99879
Loading
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
import json
import os
import paramiko
import scp
import sys

from tape_task import TapeTask
@@ -15,6 +17,7 @@ class TapeClient(object):
        self.password = password
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.scp = None
        self.taskList = []
    
    # Connects to the tape library frontend
@@ -54,6 +57,17 @@ class TapeClient(object):
        else:
            sys.exit("cmd_exit_code = FAILURE")
            
    def copy(self, srcPath, destPath):
        self.scp = scp.SCPClient(self.client.get_transport())
        print(f"Copying {srcPath} in {destPath}")
        if os.path.isdir(srcPath):
            self.scp.put(srcPath, recursive = True, remote_path = destPath)
        elif os.path.isfile(srcPath):
            self.scp.put(srcPath, destPath)
        else:
            sys.exit("This is a special file!")
        self.scp.close()    
    
    # Closes the connection
    def disconnect(self):
        self.client.close()
@@ -62,6 +76,8 @@ class TapeClient(object):
# Test
tc = TapeClient("192.168.56.101", 22, "root", "ibm")
tc.connect()
tc.copy("/home/curban/store/mydir", "/home/mydir")
tc.copy("/home/curban/store/foo2.txt", "/home/mydir/foo2.txt")
tl = tc.getTaskList()
tc.disconnect()
for i in tl: