如何 运行 使用 sftp 或 ssh 或 paramiko 自定义命令
how to run custom commands using sftp or ssh or paramiko
吨
我有以下代码,它使用 ssh 和 sftp 通过 ssh 连接到网络上的构建服务器和 运行 本机 mkdir 和 chdir 命令,我如何 运行 使用我在本地安装的一些可执行文件的任何自定义命令构建服务器?
import paramiko
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect('buildservername', username='yadomi', password='password')
sftp = ssh.open_sftp()
sftp.chdir('/local/mnt/workspace/newdir')
commandstring = 'repo init -u git://git.company.com/platform/manifest -b branchname --repo-url=git://git.company.com/tools/repo.git --repo-branch=caf/caf-stable'
si,so,se = ssh.exec_command(commandstring)
readList = so.readlines()
print readList
print se
错误:-
<paramiko.ChannelFile from <paramiko.Channel 1 (closed) -> <paramiko.Transport at 0x2730310L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
1) 您打开了一个 SFTP 通道并设置了它的工作目录,但您从未对该通道进行任何其他操作。也许您认为这会为后续 exec_command
设置工作目录?它没有。
2) 你做了 print se
,但不识别输出。也许您认为打印来自调用命令的错误流?它没有。
试试这个:
import paramiko
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect('buildservername', username='yadomi', password='password')
commandstring = 'cd /local/mnt/workspace/newdir ; repo init -u git://git.company.com/platform/manifest -b branchname --repo-url=git://git.company.com/tools/repo.git --repo-branch=caf/caf-stable'
si,so,se = ssh.exec_command(commandstring)
readList = so.readlines()
errList = se.readlines()
print readList
print errList
您的字面问题“我如何 运行 使用我在构建服务器上本地安装的一些可执行文件的任何自定义命令?”的答案是 "by passing the appropriate command line to ssh.exec_command()
".
吨 我有以下代码,它使用 ssh 和 sftp 通过 ssh 连接到网络上的构建服务器和 运行 本机 mkdir 和 chdir 命令,我如何 运行 使用我在本地安装的一些可执行文件的任何自定义命令构建服务器?
import paramiko
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect('buildservername', username='yadomi', password='password')
sftp = ssh.open_sftp()
sftp.chdir('/local/mnt/workspace/newdir')
commandstring = 'repo init -u git://git.company.com/platform/manifest -b branchname --repo-url=git://git.company.com/tools/repo.git --repo-branch=caf/caf-stable'
si,so,se = ssh.exec_command(commandstring)
readList = so.readlines()
print readList
print se
错误:-
<paramiko.ChannelFile from <paramiko.Channel 1 (closed) -> <paramiko.Transport at 0x2730310L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
1) 您打开了一个 SFTP 通道并设置了它的工作目录,但您从未对该通道进行任何其他操作。也许您认为这会为后续 exec_command
设置工作目录?它没有。
2) 你做了 print se
,但不识别输出。也许您认为打印来自调用命令的错误流?它没有。
试试这个:
import paramiko
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect('buildservername', username='yadomi', password='password')
commandstring = 'cd /local/mnt/workspace/newdir ; repo init -u git://git.company.com/platform/manifest -b branchname --repo-url=git://git.company.com/tools/repo.git --repo-branch=caf/caf-stable'
si,so,se = ssh.exec_command(commandstring)
readList = so.readlines()
errList = se.readlines()
print readList
print errList
您的字面问题“我如何 运行 使用我在构建服务器上本地安装的一些可执行文件的任何自定义命令?”的答案是 "by passing the appropriate command line to ssh.exec_command()
".