paramiko

Paramiko hanging during authentication, when runned by dint of unittest runner

 ̄綄美尐妖づ 提交于 2019-12-02 02:29:12
Good day. I have a strange problem with paramiko ssh client. Connect paramiko method hangs when it's called outside unittest2 classes/functions and code was run by unittest runner. There is a piece of code, where problem appears: import paramiko import unittest2 ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('172.18.67.10', username='root', password='secrete') _, stdout, _ = ssh.exec_command('date') class TestTest(unittest2.TestCase): def setUp(self): pass If I move ssh.connect into TestTest class or setUpModule function, connection will be

Paramiko hanging during authentication, when runned by dint of unittest runner

最后都变了- 提交于 2019-12-02 01:42:36
问题 Good day. I have a strange problem with paramiko ssh client. Connect paramiko method hangs when it's called outside unittest2 classes/functions and code was run by unittest runner. There is a piece of code, where problem appears: import paramiko import unittest2 ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('172.18.67.10', username='root', password='secrete') _, stdout, _ = ssh.exec_command('date') class TestTest(unittest2.TestCase): def

Paramiko “Invalid command” when trying non-standard command for Vyatta

拜拜、爱过 提交于 2019-12-02 00:15:17
I've just tried to connect my Python/Django app with Vyatta server using Paramiko for SSHing. Unfortunately, when I try to run show interfaces it throws "Invalid command". However, if try to SSH manually from that server, it works fine. I tried also '/vbash -c "show interfaces"' - the same result. ssh = paramiko.SSHClient() ssh.connect('10.0.0.1','vyatta','vyatta') stdin, stdout, stderr = ssh.exec_command('show interfaces') # or stdin, stdout, stderr = ssh.exec_command('vbash -c "show interfaces"') print '-'.join(stdout) print '-'.join(stderr) As mentioned earlier you can use vyatta-cfg-cmd

python

落花浮王杯 提交于 2019-12-01 19:58:28
一:简介 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接。 由于使用的是python这样的能够跨平台运行的语言,所以所有python支持的平台,如Linux, Solaris, BSD, MacOS X, Windows等,paramiko都可以支持,因此,如果需要使用SSH从一个平台连接到另外一个平台,进行一系列的操作时,paramiko是最佳工具之一。 举个常见的例子,现有这样的需求:需要使用windows客户端,远程连接到Linux服务器,查看上面的日志状态,大家通常使用的方法会是: 1:用telnet 2:用PUTTY 3:用WinSCP 4:用XManager等… 那现在如果需求又增加一条,要从服务器上下载文件,该怎么办?那常用的办法可能会是: 1:Linux上安装FTP并配置 2:Linux上安装Sambe并配置… 大家会发现,常见的解决方法都会需要对远程服务器必要的配置,如果远程服务器只有一两台还好说,如果有N台,还需要逐台进行配置,或者需要使用代码进行以上操作时,上面的办法就不太方便了。 使用paramiko可以很好的解决以上问题,比起前面的方法,它仅需要在本地上安装相应的软件(python以及PyCrypto),对远程服务器没有配置要求,对于连接多台服务器,进行复杂的连接操作特别有帮助。 二:安装

Can I get the exit code of a command executed in a subshell via ssh?

ぃ、小莉子 提交于 2019-12-01 18:14:43
I'm trying to use Paramiko to write a deployment script, and I'm having trouble with exit codes from the commands I run. I'm using code similar to that in this answer , but it's a little more complicated. Basically, from our dev boxes we have to go through a jump server, and from there to a series of production machines. Once there we have to switch to a system user (sudo su - systemuser) and then we can run commands. The problem is that as I understand it I have 3 subshells - the ssh session, the nested ssh command and then the su subshell. I can't get Paramiko to give me back the exit code

Python Paramiko timeout with long execution, need full output

被刻印的时光 ゝ 提交于 2019-12-01 17:49:28
There's lots of topics touching on part of the title, but nothing that quite satisfies the whole thing. I'm pushing a command on a remote server and need the full output after a long execution time, say 5 minutes or so. Using channel I was able to set a timeout, but when I read back stdout I got only a small portion of output. The solution seemed to be to wait for channel.exit_status_ready(). This worked on a successful call, but a failed call would never trigger the channel timeout. Having reviewed the docs, I theorize that's because the timeout only works on a read operation, and waiting for

IOError: [Errno 2] No such file - Paramiko put()

两盒软妹~` 提交于 2019-12-01 16:27:11
问题 I'm uploading a file via SFTP using Paramiko with sftp.put(localFile, remoteFile) . I make the necessary directory first if needed with makeCommand = 'mkdir -p "' + remotePath + '"' ssh.exec_command(makeCommand) this was works sometimes but I'm occasionally getting the following error: sftp.put(localFile, remoteFile) File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 565, in put File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 245, in open File "build

Recursive SFTP listdir in Python?

十年热恋 提交于 2019-12-01 13:53:22
I need to recursively list the content of a directory that contains a lot of subdirectories (more than 16,000). I am currently using Paramiko's SFTP client , which doesn't offer any recursive listdir functionality. So I have to first run listdir on the parent folder, and then another listdir for each of the (many, many) subdirectories. It takes too long to run. Is there any way to run the recursive listdir in a single SFTP call? I'm not limited to the Paramiko package, it's just the package that we're currently using. I cannot use Paramiko's ssh.exec_command('ls -R <path>') due to local

Running an SFTP operation as a different user via Python Paramiko

别来无恙 提交于 2019-12-01 13:30:34
I want connect to my Ubuntu server using a service account but perform file transfer operations on behalf of another user. My sshd_config has the following content (among other stuff): PubKeyAuthentication yes PasswordAuthentication yes Subsystem sftp /usr/lib/openssh/sftp-server I have tried the following code but without any success: t = paramiko.Transport(('<address>', <port>)) t.connect(username='serviceAccount', password='<password>') channel = t.open_session() channel.exec_command('sudo su -l <other user> -c /usr/lib/openssh/sftp-server') sftp = t.open_sftp_client() file = sftp.file("

Recursive SFTP listdir in Python?

我们两清 提交于 2019-12-01 12:32:53
问题 I need to recursively list the content of a directory that contains a lot of subdirectories (more than 16,000). I am currently using Paramiko's SFTP client, which doesn't offer any recursive listdir functionality. So I have to first run listdir on the parent folder, and then another listdir for each of the (many, many) subdirectories. It takes too long to run. Is there any way to run the recursive listdir in a single SFTP call? I'm not limited to the Paramiko package, it's just the package