paramiko

Upload files using SFTP in Python, but create directories if path doesn't exist

落爺英雄遲暮 提交于 2019-12-02 18:10:30
I want to upload a file on a remote server with Python. I'd like to check beforehand if the remote path is really existing, and if it isn't, to create it. In pseudocode: if(remote_path not exist): create_path(remote_path) upload_file(local_file, remote_path) I was thinking about executing a command in Paramiko to create the path (e.g. mkdir -p remote_path ). I came up with this: # I didn't test this code import paramiko, sys ssh = paramiko.SSHClient() ssh.connect(myhost, 22, myusername, mypassword) ssh.exec_command('mkdir -p ' + remote_path) ssh.close transport = paramiko.Transport((myhost, 22

How can I inherit parent logger when using Python's multiprocessing? Especially for paramiko

一世执手 提交于 2019-12-02 17:23:16
问题 I'm using Python's multiprocessing. I have set the logger in parent process, but I can't just simply inherit the parent's logging setting. I don't worry about mixing up the log, for I use multiprocessing not for running jobs concurrently, but for time controlling, so only one sub process is running at same time. My code without multiprocessing: from multiprocessing import Process import paramiko import logging import sys def sftp_read(): # log.debug("Child process started") # This line will

Using paramiko with socks proxy

喜夏-厌秋 提交于 2019-12-02 10:56:56
I an trying to use paramiko with socks proxy (SecureCRT or putty) configured as socks proxy. I am using the below code and import paramiko,socks host, port = '127.0.0.1', 1080 # Set up your proxy information for this socket sock=socks.socksocket() sock.set_proxy( proxy_type=socks.SOCKS4, addr=host, port=port, ) # Connect the socket sock.connect((host, port)) # Create your Paramiko Transport transport = paramiko.Transport(sock) transport.connect( username='username', #<------not sure if it is needed, the socks proxy needs no username/password password='secret', ) client = paramiko.client

python paramiko module error with callback

对着背影说爱祢 提交于 2019-12-02 10:33:14
问题 I'm trying to use the paramiko module to copy a (big) file in my local network, and get the output to display a GtkProgressBar. A part of my code is: ... NetworkCopy.pbar.set_text("Copy of the file in the Pi...") while gtk.events_pending(): # refresh the progress bar gtk.main_iteration() self.connection(transferred, toBeTransferred) def connection(self, transferred, toBeTransferred): sftp = self.sftp fichier_pc = self.fichier_pc chemin_pi = self.chemin_pi # var names are in french ! fichier =

What is the difference between calling open_sftp() locally and via a separate function?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 05:55:13
问题 In the following code, the first test passes, and the second one does not, which I find puzzling. import paramiko def test1(): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect('10.0.0.107', username='test', password='test') sftp = client.open_sftp() sftp.stat('/tmp') sftp.close() def get_sftp(): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect('10.0.0.107', username='test',

SSHException: Error reading SSH protocol banner

让人想犯罪 __ 提交于 2019-12-02 05:02:45
当我在使用ssh 远程connect 另一台机器的server 时出现了错误,错误如下,起初以为是自己代码写的有问题,后来本地了一下看了跑的没问题,我就开始根据报错去查寻原因, 起初在论坛博客看到这篇文章,试着看了下意思就是你的self.banner默认源码时间设置只有15s 让我修改源码在transform.py 然后离线安装paramiko ,试了后还是报上面的错,试了下还是没什么用网友的技术贴并不是都实用还得靠自己啊,这里的问题可以排除了,继续找原因,查看sshd端口 paramiko Exception: Error reading SSH protocol banner File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 2044, in _check_banner buf = self.packetizer.readline(timeout) 修改:self.banner_timeout = 15 self.banner_timeout = 300 下载:https://src.fedoraproject.org/repo/pkgs/python-paramiko/ 源码. 我选了:paramiko-1.15.2.tar.gz tar -xzvf paramiko-1.15

python paramiko module error with callback

╄→гoц情女王★ 提交于 2019-12-02 04:41:31
I'm trying to use the paramiko module to copy a (big) file in my local network, and get the output to display a GtkProgressBar. A part of my code is: ... NetworkCopy.pbar.set_text("Copy of the file in the Pi...") while gtk.events_pending(): # refresh the progress bar gtk.main_iteration() self.connection(transferred, toBeTransferred) def connection(self, transferred, toBeTransferred): sftp = self.sftp fichier_pc = self.fichier_pc chemin_pi = self.chemin_pi # var names are in french ! fichier = self.fichier transferred = self.transferred toBeTransferred = self.toBeTransferred print "Transferred:

Getting “socket.error: [Errno 61] Connection refused” python paramiko

白昼怎懂夜的黑 提交于 2019-12-02 04:09:43
问题 Getting error connection refused error when trying to connect to the host to copy a local file to the host server. Don't have any issue connecting to the server remotely though. host = "9.29.22.222" username = "XXX" password = "XXX" local_path = "/Users/samuelhii/Desktop/file.txt" remote_path = "C:\Program Files (x86)\file.txt" s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) s.connect(host,22,username,password) sftp = s.open_sftp() sftp.put(local_path,remote

Use Paramiko's stdout as stdin with subprocess

拈花ヽ惹草 提交于 2019-12-02 03:32:11
How can I execute a command on a remote server in Python and pipe the stdout to a local command? To do ssh host 'echo test' | cat in Python, I have tried import paramiko import subprocess ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('host', username='user') ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('echo test') proc = subprocess.Popen(['cat'], stdin=ssh_stdout) outs, errs = proc.communicate() print(outs) but I get the exception 'ChannelFile' object has no attribute 'fileno' . It seems that Paramiko's ssh_stdout can't be used as

How to remove lines from stdout in python?

自闭症网瘾萝莉.ら 提交于 2019-12-02 02:31:24
I have a program that grabs some data through ssh using paramiko: ssh = paramiko.SSHClient() ssh.connect(main.Server_IP, username=main.Username, password=main.Password) ssh_stdin_host, ssh_stdout_host, ssh_stderr_host =ssh_session.exec_command(setting.GetHostData) I would like to remove the first 4 lines from ssh_stdout_host. I've tried using StringIO to use readlines like this: output = StringIO("".join(ssh_stdout_host)) data_all = output.readlines() But I'm lost after this. What would be a good approach? Im using python 2.6.5. Thanks. readlines provides all the data allLines = [line for line