Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import libssh2, socket, os
- SERVER = 'someserver'
- username = 'someuser'
- password = 'secret!'
- sourceFilePath = 'source/file/path'
- destinationFilePath = 'dest/file/path'
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((SERVER, 22))
- session = libssh2.Session()
- session.startup(sock)
- session.userauth_password(username, password)
- sourceFile = open(sourceFilePath, 'rb')
- channel = session.scp_send(destinationFilePath, 0o644, os.stat(sourceFilePath).st_size)
- while True:
- data = sourceFile.read(4096)
- if not data:
- break
- channel.write(data)
- exitStatus = channel.exit_status()
- channel.close()
- import libssh2, socket, os
- SERVER = 'someserver'
- username = 'someuser'
- password = 'secret!'
- sourceFilePath = 'source/file/path'
- destinationFilePath = 'dest/file/path'
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((SERVER, 22))
- session = libssh2.Session()
- session.startup(sock)
- session.userauth_password(username, password)
- (channel, (st_size, _, _, _)) = session.scp_recv(sourceFilePath, True)
- destination = open(destinationFilePath, 'wb')
- got = 0
- while got < st_size:
- data = channel.read(min(st_size - got, 1024))
- got += len(data)
- destination.write(data)
- exitStatus = channel.get_exit_status()
- channel.close()
- import os
- 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