How to use scp - 10 common examples

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 ManageIQ / integration_tests / utils / composite.py View on Github external
allow_agent=False,
            look_for_keys=False,
            gss_auth=False)
    scp = None

    while True:
        source, destination, item, items_done = rc._queue.get()
        destination = local(destination)
        destination_dir = local(destination.dirname)
        destination_dir.ensure(dir=True)
        if not destination.check():
            if scp is None:
                scp = SCPClient(client.get_transport())
            try:
                scp.get(source, destination.strpath)
            except SCPException:
                # remote destination didn't exist
                pass
            except (SSHException, socket.timeout):
                # SSH blew up :(
                rc._queue.put((source, destination, item, items_done))
                rc._queue.task_done()
                continue
        rc._progress_update(item, items_done)
        rc._queue.task_done()
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 liwonace / lsiem / src / hash / scphash.py View on Github external
try:
    sys.argv[1]
except IndexError:
    print("usage: python scphash.py [hostname] [username] [password] [filename] [hash algorism]")
    print("[[hash algorism number]] 1: MD5, 2: SHA-1, 3: SHA-256, 4: SHA-512")
    sys.exit(1)

ssh = SSHClient()
ssh.load_system_host_keys()
# ssh.connect('192.168.7.71',username='root',password='lwa123*')
# print(sys.argv[1], type(sys.argv[1]))
ssh.connect(sys.argv[1], username=sys.argv[2], password=sys.argv[3])

# SCPCLient takes a paramiko transport as an argument
scp = SCPClient(ssh.get_transport())

# Uploading the 'test' directory with its content in the
# '/home/user/dump' remote directory
scp.put(sys.argv[4], recursive=True, remote_path='/home/lsiem/')

# send hash value file 
BLOCKSIZE = 65536

if sys.argv[5] == '1':
    hasher = hashlib.md5()
elif sys.argv[5] == '2':
    hasher = hashlib.sha1()
elif sys.argv[5] == '3':
    hasher = hashlib.sha256()
elif sys.argv[5] == '4':
    hasher = hashlib.sha512()
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)

scp

scp module for paramiko

LGPL-2.1
Latest version published 5 months ago

Package Health Score

88 / 100
Full package analysis