pdf SCP
Par keyphrene, Thursday 18 September 2008 à 18:01 :: Org.keyphrene - 4Py :: #13 :: rss
Transfert By SCP
Transfert By SCP
import socket from org.keyphrene import SSH2 # or # from ssh4py import SSH2 HOSTNAME = "127.0.0.1" PORT = 22 LOGIN = "login" PWD = "password" # A simple connection sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOSTNAME, PORT)) sock.setblocking(1) ssh = SSH2.Session() ssh.setBanner(SSH2.DEFAULT_BANNER+" Python (http://www.keyphrene.com/projects/org.keyphrene)") ssh.startup(sock) ssh.setPassword(LOGIN, PWD) # Get File by SCP channel = ssh.SCPGet('"/path/to/filename.txt"') while 1: data = channel.read(1024) if not data: break print data channel.close() # Put file by SCP f = open("/path/to/filename.txt", "rb") channel = ssh.SCPPut('"/path/to/filename.txt"', 0755, os.stat("/path/to/filename.txt").st_size) while 1: data = f.read(1024) if not data: break channel.write(data) channel.close() f.close() ssh.close()

Comments
No comment for this moment.
Add a comment