# -*- coding: utf-8 -*- import paramiko import os def ssh_command(command): client = paramiko.client.SSHClient() client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) client.connect('ip',port=22,username='root',password="password") stdin,stdout,stderr = client.exec_command(f"{command}",timeout=60) result = stdout.read() result = result.decode('utf-8'); print(result) client.close() def sftp_upload_file(local_file,server_file): transport = paramiko.Transport(('ip', 22)) transport.connect(username='root', password='root.123') sftp = paramiko.SFTPClient.from_transport(transport) sftp.put(local_file,server_file) local_path = os.getcwd() ssh_command(""" cat > 1.sh <<EOF # create 1.sh echo \`date\` EOF """) sftp_upload_file(f'{local_path}/2.txt',"/root/1.txt") ssh_command('ls')
python ssh登入
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
解决 ESX ssh root 登入失败
1. vsphere client 添加用户 ,赋予shell2. 加入权限 3. 登入 后 su - 切换
解决 休闲 ESX ssh root 登入失败