Guest User

Untitled

a guest
Sep 15th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import libssh2, socket, os
  2.  
  3. SERVER = 'someserver'
  4. username = 'someuser'
  5. password = 'secret!'
  6.  
  7. sourceFilePath = 'source/file/path'
  8. destinationFilePath = 'dest/file/path'
  9.  
  10. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11. sock.connect((SERVER, 22))
  12.  
  13. session = libssh2.Session()
  14. session.startup(sock)
  15.  
  16. session.userauth_password(username, password)
  17.  
  18. sourceFile = open(sourceFilePath, 'rb')
  19.  
  20. channel = session.scp_send(destinationFilePath, 0o644, os.stat(sourceFilePath).st_size)
  21.  
  22. while True:
  23. data = sourceFile.read(4096)
  24. if not data:
  25. break
  26. channel.write(data)
  27.  
  28. exitStatus = channel.exit_status()
  29. channel.close()
  30.  
  31. import libssh2, socket, os
  32.  
  33. SERVER = 'someserver'
  34. username = 'someuser'
  35. password = 'secret!'
  36.  
  37. sourceFilePath = 'source/file/path'
  38. destinationFilePath = 'dest/file/path'
  39.  
  40.  
  41. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  42. sock.connect((SERVER, 22))
  43.  
  44. session = libssh2.Session()
  45. session.startup(sock)
  46.  
  47. session.userauth_password(username, password)
  48. (channel, (st_size, _, _, _)) = session.scp_recv(sourceFilePath, True)
  49.  
  50. destination = open(destinationFilePath, 'wb')
  51.  
  52. got = 0
  53. while got < st_size:
  54. data = channel.read(min(st_size - got, 1024))
  55. got += len(data)
  56. destination.write(data)
  57.  
  58. exitStatus = channel.get_exit_status()
  59. channel.close()
  60.  
  61. import os
  62.  
  63. os.system("sshpass -p 'your password' scp /opt/pysftp_server.txt root@172.19.113.87:/home")
Add Comment
Please, Sign In to add comment