How to use the scp.SCPClient function in scp

To help you get started, we’ve selected a few scp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hwang595 / ps_pytorch / distributed_TF / tools / tf_ec2.py View on Github external
for instance in running_instances:
          if instance.instance_id in instance_ids:
             selected_instance = instance
       if selected_instance == None:
          print("Error, no instance in instance cluster: %s" % cluster_instance_string)
          sys.exit(0)

       # For the selected instance, ssh and compress the directory
       file_to_download = configuration["base_out_dir"] + "/" + filepath
       name = configuration["name"] + "_data_" + filepath
       copy_command = "cp -r %s ./%s" % (file_to_download, name)
       run_ssh_commands(instance, [copy_command])

       # SCP the data over to the local machine
       client = connect_client(selected_instance)
       scp = SCPClient(client.get_transport())
       local_path = outpath + name
       print("SCP %s to %s" % (name, local_path))
       scp.get("%s" % name, local_path=local_path)
       scp.close()
       client.close()

       return local_path
github nre-learning / nrelabs-curriculum / lessons / fundamentals / lesson-99-cumulus-demo / stage1 / configs / leaf1.py View on Github external
import paramiko
import os
from scp import SCPClient

host=os.environ['SYRINGE_TARGET_HOST']

def createSSHClient(server, port, user, password):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(server, port, user, password)
    return client

ssh=createSSHClient(host,22,"antidote","antidotepassword")

scp=SCPClient(ssh.get_transport())

scp.put('/antidote/stage1/configs/leaf1/interfaces', '/home/antidote/interfaces')
scp.put('/antidote/stage1/configs/leaf1/daemons', '/home/antidote/daemons')
scp.put('/antidote/stage1/configs/leaf1/frr.conf', '/home/antidote/frr.conf')


ssh.exec_command('sudo cp /home/antidote/interfaces /etc/network/interfaces')
ssh.exec_command('sudo cp /home/antidote/daemons /etc/frr/daemons')
ssh.exec_command('sudo cp /home/antidote/frr.conf /etc/frr/frr.conf')
ssh.exec_command('sudo systemctl restart frr.service')
ssh.exec_command('sudo ifreload -a')

scp.close()
ssh.close()
github wylok / sparrow / Modules / SSH.py View on Github external
def Scp(self,src,dst):
        scp = SCPClient(self._ssh.get_transport())
        stderr = scp.put(src,dst,recursive=True)
        if stderr:
            return stderr
github nre-learning / nrelabs-curriculum / lessons / fundamentals / lesson-98-frr / stage1 / configs / branch-2.py View on Github external
import paramiko
from glob import glob
import os
from scp import SCPClient

host=os.environ['SYRINGE_TARGET_HOST']

def createSSHClient(server, port, user, password):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(server, port, user, password)
    return client

ssh=createSSHClient(host,22,"antidote","antidotepassword")

scp=SCPClient(ssh.get_transport())

#Change hostname

ssh.exec_command("sudo sed -E -i 's/^(127\.0\.1\.1\s+).*/\\1branch-2/' /etc/hosts")  
ssh.exec_command("sudo printf '%s' 'branch-2' > /etc/hostname") 
ssh.exec_command("sudo hostname branch-2")

#Copy configuration files over

ssh.exec_command('sudo cp /antidote/stage1/configs/branch-2/interfaces /etc/network/interfaces')
ssh.exec_command('sudo cp /antidote/stage1/configs/branch-2/daemons /etc/frr/daemons')
ssh.exec_command('sudo cp /antidote/stage1/configs/branch-2/*.conf /etc/frr')

ssh.exec_command('sudo chown frr:frr /etc/frr/*.conf')
ssh.exec_command('sudo chown frr:frrvty /etc/frr/vtysh.conf')
ssh.exec_command('sudo chmod 640 /etc/frr/*.conf')
github jbardin / scp.py / scp.py View on Github external
This is a convenience function that creates a SCPClient from the given
    transport and closes it at the end, useful for one-off transfers.

    @param files: A single path, or a list of paths to be transferred.
        recursive must be True to transfer directories.
    @type files: string OR list of strings
    @param remote_path: path in which to receive the files on the remote host.
        defaults to '.'
    @type remote_path: str
    @param recursive: transfer files and directories recursively
    @type recursive: bool
    @param preserve_times: preserve mtime and atime of transferred files and
        directories.
    @type preserve_times: bool
    """
    with SCPClient(transport) as client:
        client.put(files, remote_path, recursive, preserve_times)
github rapid7 / insightconnect-plugins / cisco_firepower / komand_cisco_firepower / actions / map_insightvm_vulnerability_to_host_database / action.py View on Github external
self.logger.info(f"Total records to process: {total}")
        payload = generate_payload(vuln_objects, operation, 9223372036854775807) # Python 2 max int, we don't need paging

        f = open(self.FIREPOWER_FILENAME, "w")
        f.write(payload[0])
        f.close()

        ssh = SSHClient()
        ssh.load_system_host_keys()
        # ssh connect
        ssh.connect(self.connection.host, username=user, password=password, timeout=60)

        transport = ssh.get_transport()

        scp = SCPClient(transport)
        scp.put(self.FIREPOWER_FILENAME)

        session = transport.open_session()
        session = transport.open_session()
        session.set_combine_stderr(True)
        session.get_pty()
        stdin, stdout, stderr = session.exec_command(f"nmimport.pl {self.FIREPOWER_FILENAME}")

        if stderr:
            raise PluginException(cause="SSH to Firepwoerfailed",
                                  assistance=str(stderr))

        return {
            Output.Message: stdout
        }
github CyberReboot / poseidon / poseidon / controllers / faucet / connection.py View on Github external
def send_file(self, f_type):
        # TODO option to send other files (config can be multiple files)
        if self.host:
            self._connect()
            # TODO better logging
            try:
                scp = SCPClient(self.ssh.get_transport())
                if f_type == 'config':
                    scp.put(os.path.join(self.config_dir, 'faucet.yaml'),
                            self.config_file)
                elif f_type == 'log':
                    scp.put(os.path.join(self.log_dir, 'faucet.log'),
                            self.log_file)
                else:
                    pass
                scp.close()
            except Exception as e:  # pragma: no cover
                self.logger.error(
                    'failed to send file {0} because: {1}'.format(f_type, e))
            self._disconnect()
github ANRGUSC / Jupiter / circe / rt_profiler_data_update.py View on Github external
node_name         = os.environ['NODE_NAME']
    local_input_path  = '/centralized_scheduler/runtime/droplet_runtime_input_' + node_name
    local_output_path = '/centralized_scheduler/runtime/droplet_runtime_output_' + node_name

    """
        Check if the files exists. 
    """
    while True:
        if path.isfile(local_input_path) and path.isfile(local_output_path):
            client = paramiko.SSHClient()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            remote_path = dir_remote
            while retry < num_retries:
                try:
                    client.connect(scheduler_IP, username=username, password=password, port=ssh_port)
                    scp = SCPClient(client.get_transport())
                    scp.put(local_input_path, remote_path)
                    scp.put(local_output_path, remote_path)
                    scp.close() 
                    os.remove(local_input_path)
                    os.remove(local_output_path)
                    print('Runtime data transfer complete\n')
                    break
                except:
                    print('SSH Connection refused or Some Connection Error, will retry in 2 seconds')
                    time.sleep(2)
                    retry += 1
        else:
            print('No Runtime data file exists...')

        time.sleep(300)
github bluecatlabs / gateway-workflows / Community / bulk_register_mac_address / migration.py View on Github external
def upload_migration_xml(api, workflow_dir, filename):
    hostname = urlparse(api.get_url()).hostname
    print('Hostname: %s' % hostname)
    ssh = SSHClient()
    ssh.set_missing_host_key_policy(AutoAddPolicy())
    ssh.connect(hostname, username='root', password='root')
    
    scp = SCPClient(ssh.get_transport())
    scp.put(workflow_dir + '/' + filename, '/data/migration/incoming/')
github eNMS-automation / eNMS / eNMS / models / execution.py View on Github external
def transfer_file(self, ssh_client, files):
        if self.protocol == "sftp":
            with SFTPClient.from_transport(
                ssh_client.get_transport(),
                window_size=self.window_size,
                max_packet_size=self.max_transfer_size,
            ) as sftp:
                for source, destination in files:
                    getattr(sftp, self.direction)(source, destination)
        else:
            with SCPClient(ssh_client.get_transport()) as scp:
                for source, destination in files:
                    getattr(scp, self.direction)(source, destination)

scp

scp module for paramiko

LGPL-2.1
Latest version published 6 months ago

Package Health Score

88 / 100
Full package analysis