paramiko

Connecting to remote PostgreSQL database over SSH tunnel using Python

家住魔仙堡 提交于 2019-12-19 04:04:29
问题 I have a problem with connecting to a remote database using SSH tunnel (now I'm trying with Paramiko). Here is my code: #!/usr/bin/env python3 import psycopg2 import paramiko import time #ssh = paramiko.SSHClient() #ssh.load_system_host_keys() #ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #ssh.connect('pluton.kt.agh.edu.pl', 22, username='aburban', password='pass') t = paramiko.Transport(('pluton.kt.agh.edu.pl', 22)) t.connect(username="aburban", password='pass') c = paramiko

paramiko hangs on get after ownloading 20 MB of file

拟墨画扇 提交于 2019-12-18 17:28:18
问题 I am in need of python sftp client to download files from a sftp server. I started to use Paramiko. Small files in KB works well but however when I try to download 600 MB of file, it hangs indefinitely after downloading 20 MB of file. Unable to figure out what the issue is. Increasing the window size did not solve either. Any help would be much appreciated! host = config.getsafe(section, "host") username = config.getsafe(section, "username") port = config.getsafe(section, "port") remote_dir =

How to keep ssh session not expired using paramiko?

北战南征 提交于 2019-12-18 15:54:49
问题 I intend to run several commands on remote host using paramiko, but the ssh session closed after running a command. The code listed below: from paramiko import SSHClient import paramiko ssh = SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(host, 22, user, passwd, timeout=3) stdin, stdout, stderr = ssh.exec_command('uname -a') So is there any way to stop the ssh session from closing? Or any alternatives for paramiko? Update : I was

How to know if a paramiko SSH channel is disconnected?

久未见 提交于 2019-12-18 13:07:44
问题 I'm desinging test cases in which I use paramiko for SSH connections. Test cases usually contain paramiko.exec_command() calls which I have a wrapper for (called run_command() ). Here self.ssh is an intance of paramiko.SSHClient() . I use a decorator to check the ssh connection before each call. ( self.get_ssh() negotiates the connection) def check_connections(function): ''' A decorator to check SSH connections. ''' def deco(self, *args, **kwargs): if self.ssh is None: self.ssh = self.get_ssh

Not able to navigate to desired folder on remote Linux machine, how do i do that using paramiko?

十年热恋 提交于 2019-12-18 09:52:24
问题 I am Using Pyhton paramiko and My website server has folder structure like this- 1]dir1 --dirP --dirQ 2]dir2 --dirA --file.sh --dirB 3]dir3 where i want to access file.sh from dirA inside dir2 folder I tried this- import paramiko client.connect('mysite.com', username='something', password='something') stdin, stdout, stderr = client.exec_command('cd dir2') stdin, stdout, stderr = client.exec_command('ls') for line in stdout: print('... ' + line.strip('\n')) but i get output- ...dir1 ...dir2 ..

Paramiko capturing command output

坚强是说给别人听的谎言 提交于 2019-12-18 09:40:58
问题 I have an issue that has been giving me a headache for a few days. I am using the Paramiko module with Python 2.7.10 and I'd like to issue multiple commands to a Brocade router, but only return output from one of the given commands like so: #!/usr/bin/env python import paramiko, time router = 'r1.test.example.com' password = 'password' username = 'testuser' ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(router, username=username, password

Python - Upload a in-memory file (generated by API calls) in FTP by chunks

╄→尐↘猪︶ㄣ 提交于 2019-12-18 07:19:58
问题 I need to be able to upload a file through FTP and SFTP in Python but with some not so usual constraints. File MUST NOT be written in disk. The file how it is generated is by calling an API and writing the response which is in JSON to the file. There are multiple calls to the API. It is not possible to retrieve the whole result in one single call of the API. I can not store in a string variable the full result by doing the multiple calls needed and appending in each call until I have the

Use Paramiko AutoAddPolicy with pysftp

自闭症网瘾萝莉.ら 提交于 2019-12-18 04:21:51
问题 This code is not working: def sftp_connection(self): import pysftp connection = pysftp.Connection(self.host, username=self.system_name, private_key=os.path.join(HOME, '.ssh', 'id_rsa')) # in the next lines I try to use AutoAddPolicy client = connection.sftp_client() client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts')) client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy) return connection This is the exception: Traceback (most recent call last): File "/home/u/src/myapp

“Failed to load HostKeys” warning while connecting to SFTP server with pysftp

怎甘沉沦 提交于 2019-12-17 20:42:01
问题 I wrote a Python script to connect to SFTP server using key authentication. It connects to server successfully but shows the following warning (see below). What does it mean and how to remove it. What changes has to made in code? My code: import os import pysftp import socket import paramiko import time import os.path import shutil IP = "127.0.X.X" myUsername = "USERNAME" port = 22 cnopts = pysftp.CnOpts() cnopts.hostkeys = None import os privatekeyfile = os.path.expanduser("C:\\Users\\Rohan\

Execute multiple dependent commands individually with Paramiko and find out when each command finishes

妖精的绣舞 提交于 2019-12-17 20:33:14
问题 I am writing a program in Python which must communicate through SSH with a physical target, and send to this targets some commands automatically (it is for testing). I start by doing this with Paramiko and everything was perfect until I have to send several commands and when for example the second one must be execute in the context of the first (for example the first one makes cd /mytargetRep and the second one is ./executeWhatIWant ). I can't use exec_command to do so, because each exec