Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.system("scp FILE USER@SERVER:PATH")
- #e.g. os.system("scp foo.bar joe@srvr.net:/path/to/foo.bar")
- import os
- import paramiko
- ssh = paramiko.SSHClient()
- ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
- ssh.connect(server, username=username, password=password)
- sftp = ssh.open_sftp()
- sftp.put(localpath, remotepath)
- sftp.close()
- ssh.close()
- import subprocess
- p = subprocess.Popen(["scp", myfile, destination])
- sts = os.waitpid(p.pid, 0)
- from paramiko import SSHClient
- from scp import SCPClient
- ssh = SSHClient()
- ssh.load_system_host_keys()
- ssh.connect('example.com')
- with SCPClient(ssh.get_transport()) as scp:
- scp.put('test.txt', 'test2.txt')
- scp.get('test2.txt')
- #!/usr/bin/env python
- from fabric.api import execute, put
- from fabric.network import disconnect_all
- if __name__=="__main__":
- import sys
- # specify hostname to connect to and the remote/local paths
- srcdir, remote_dirname, hostname = sys.argv[1:]
- try:
- s = execute(put, srcdir, remote_dirname, host=hostname)
- print(repr(s))
- finally:
- disconnect_all()
- import pipes
- import re
- import pexpect # $ pip install pexpect
- def progress(locals):
- # extract percents
- print(int(re.search(br'(d+)%$', locals['child'].after).group(1)))
- command = "scp %s %s" % tuple(map(pipes.quote, [srcfile, destination]))
- pexpect.run(command, events={r'd+%': progress})
- from paramiko import SSHClient
- from scp import SCPClient
- ssh = SSHClient()
- ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
- ssh.connect(server, username='username', password='password')
- with SCPClient(ssh.get_transport()) as scp:
- scp.put('test.txt', 'test2.txt')
- import os
- filePath = "/foo/bar/baz.py"
- serverPath = "/blah/boo/boom.py"
- os.system("scp "+filePath+" user@myserver.com:"+serverPath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement