paramiko

With pysftp or Paramiko, how can I get a directory listing complete with attributes?

点点圈 提交于 2021-02-08 02:16:45
问题 As the title says, I'm trying to get a list of all the files and directories in a directory, including their attributes (I'm looking for at least name, size, last modified, and is it a file or a folder). I'm using Python 3 on Windows. I've tried listdir() , and I get a list of files without attributes. I've tried listdir_attr() , and I get a list of attributes, but no filenames - and I don't see anything that guarantees that those two lists will be in the same order, so as far as I know, I

With pysftp or Paramiko, how can I get a directory listing complete with attributes?

不羁的心 提交于 2021-02-08 02:16:02
问题 As the title says, I'm trying to get a list of all the files and directories in a directory, including their attributes (I'm looking for at least name, size, last modified, and is it a file or a folder). I'm using Python 3 on Windows. I've tried listdir() , and I get a list of files without attributes. I've tried listdir_attr() , and I get a list of attributes, but no filenames - and I don't see anything that guarantees that those two lists will be in the same order, so as far as I know, I

With pysftp or Paramiko, how can I get a directory listing complete with attributes?

拜拜、爱过 提交于 2021-02-08 02:13:20
问题 As the title says, I'm trying to get a list of all the files and directories in a directory, including their attributes (I'm looking for at least name, size, last modified, and is it a file or a folder). I'm using Python 3 on Windows. I've tried listdir() , and I get a list of files without attributes. I've tried listdir_attr() , and I get a list of attributes, but no filenames - and I don't see anything that guarantees that those two lists will be in the same order, so as far as I know, I

Getting “must be run from a terminal” when switching to root user using Paramiko module in Python

ぐ巨炮叔叔 提交于 2021-02-07 20:33:26
问题 I am trying to automate a task through a Python script. The idea is to login as a regular user and then send a su command and switch to the root account. The reason I can't directly login as root is that SSHD doesn't allow root logins. Here's what I have: ip='192.168.105.8' port=22 username='xyz' password='abc' ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,port,username,password) print ("SSH connection established") stdin,stdout,stderr=ssh

Python Paramiko, PermissionError: [Errno 13] Permission denied when get files from remote server

断了今生、忘了曾经 提交于 2021-02-07 10:29:04
问题 import paramiko, os paramiko.util.log_to_file('E:\Automation\paramiko.log') from stat import S_ISDIR host = "xx.xx.xxx.xxx" port = 22 transport = paramiko.Transport((host, port)) password = "password" username = "username" #transport.set_missing_host_key_policy(paramiko.AutoAddPolicy()) transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) def sftp_walk(remotepath): path=remotepath files=[] folders=[] for f in sftp.listdir_attr

Python Paramiko, PermissionError: [Errno 13] Permission denied when get files from remote server

佐手、 提交于 2021-02-07 10:26:23
问题 import paramiko, os paramiko.util.log_to_file('E:\Automation\paramiko.log') from stat import S_ISDIR host = "xx.xx.xxx.xxx" port = 22 transport = paramiko.Transport((host, port)) password = "password" username = "username" #transport.set_missing_host_key_policy(paramiko.AutoAddPolicy()) transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) def sftp_walk(remotepath): path=remotepath files=[] folders=[] for f in sftp.listdir_attr

SQLAlchemy through Paramiko SSH

耗尽温柔 提交于 2021-02-06 09:12:34
问题 I have a database on a server which I need to access through SSH. Right now I deal with the DB by using the command line to get the data. import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname='XX.XX.XX', username='user', password='pass', port = YYY) query = "mysql -u " + username_sql + " -p" + password_sql +" dbb -e \"" + sql_query + "\"" ssh.exec_command(query.decode('string_escape')) ssh.close() Is there a way to do this

SQLAlchemy through Paramiko SSH

…衆ロ難τιáo~ 提交于 2021-02-06 09:07:01
问题 I have a database on a server which I need to access through SSH. Right now I deal with the DB by using the command line to get the data. import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname='XX.XX.XX', username='user', password='pass', port = YYY) query = "mysql -u " + username_sql + " -p" + password_sql +" dbb -e \"" + sql_query + "\"" ssh.exec_command(query.decode('string_escape')) ssh.close() Is there a way to do this

SQLAlchemy through Paramiko SSH

一世执手 提交于 2021-02-06 09:06:52
问题 I have a database on a server which I need to access through SSH. Right now I deal with the DB by using the command line to get the data. import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname='XX.XX.XX', username='user', password='pass', port = YYY) query = "mysql -u " + username_sql + " -p" + password_sql +" dbb -e \"" + sql_query + "\"" ssh.exec_command(query.decode('string_escape')) ssh.close() Is there a way to do this

Python reads only last line in text file

痞子三分冷 提交于 2021-02-05 12:30:46
问题 I am trying to read 2 IP address from text file and connect these devices and run the "conf t" command on these devices. When i trying to do this job by following coding, python reads only last line in text file, not reading the first line. What should i do? Thanks. import paramiko username = "xxxx" password = "yyyy" f = open("C:\\Users\0\Desktop\\deneme.txt") for line in f: ip_address = line.strip() ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko