Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import os
  2. os.system("scp FILE USER@SERVER:PATH")
  3. #e.g. os.system("scp foo.bar joe@srvr.net:/path/to/foo.bar")
  4.  
  5. import os
  6. import paramiko
  7.  
  8. ssh = paramiko.SSHClient()
  9. ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
  10. ssh.connect(server, username=username, password=password)
  11. sftp = ssh.open_sftp()
  12. sftp.put(localpath, remotepath)
  13. sftp.close()
  14. ssh.close()
  15.  
  16. import subprocess
  17. p = subprocess.Popen(["scp", myfile, destination])
  18. sts = os.waitpid(p.pid, 0)
  19.  
  20. from paramiko import SSHClient
  21. from scp import SCPClient
  22.  
  23. ssh = SSHClient()
  24. ssh.load_system_host_keys()
  25. ssh.connect('example.com')
  26.  
  27. with SCPClient(ssh.get_transport()) as scp:
  28. scp.put('test.txt', 'test2.txt')
  29. scp.get('test2.txt')
  30.  
  31. #!/usr/bin/env python
  32. from fabric.api import execute, put
  33. from fabric.network import disconnect_all
  34.  
  35. if __name__=="__main__":
  36. import sys
  37. # specify hostname to connect to and the remote/local paths
  38. srcdir, remote_dirname, hostname = sys.argv[1:]
  39. try:
  40. s = execute(put, srcdir, remote_dirname, host=hostname)
  41. print(repr(s))
  42. finally:
  43. disconnect_all()
  44.  
  45. import pipes
  46. import re
  47. import pexpect # $ pip install pexpect
  48.  
  49. def progress(locals):
  50. # extract percents
  51. print(int(re.search(br'(d+)%$', locals['child'].after).group(1)))
  52.  
  53. command = "scp %s %s" % tuple(map(pipes.quote, [srcfile, destination]))
  54. pexpect.run(command, events={r'd+%': progress})
  55.  
  56. from paramiko import SSHClient
  57. from scp import SCPClient
  58.  
  59. ssh = SSHClient()
  60. ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
  61. ssh.connect(server, username='username', password='password')
  62. with SCPClient(ssh.get_transport()) as scp:
  63. scp.put('test.txt', 'test2.txt')
  64.  
  65. import os
  66. filePath = "/foo/bar/baz.py"
  67. serverPath = "/blah/boo/boom.py"
  68. os.system("scp "+filePath+" user@myserver.com:"+serverPath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement