python paramiko基本

时间:2024-11-23 12:07:02

基本

import paramiko

blade = '192.168.0.10'
port = 22
username = 'admin'
password = '' localpath = '/home/local/test.txt'
remotepath = '/home/remote/test/test.txt' conn_name = paramiko.SSHClient()
conn_name.load_system_host_keys()
conn_name.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn_name.connect(blade, port, username, password)
// or:
// connect(blade, username=username, password=password)
stdin, stdout, stderr = conn_name.exec_command('cd /home/remote;mkdir test;')
for line in stdout:
print line sftp = conn_name.open_sftp()
sftp.put(localpath, remotepath)
sftp.get(remotepath,localpath)
sftp.close() conn_name.close()
stdin, stdout, stderr = conn_name.exec_command('date +%s')
timestamp = stdout.read()