pysftp

Connecting to an SFTP server using pysftp and Python 3 with just the server fingerprint

馋奶兔 提交于 2019-12-08 10:05:00
问题 I'm in kind of a bizarre situation where I need to connect to an SFTP server for the first time but I can't seem to find a way to get access to the known host entry for the server.I can connect fine if I say: import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None with pysftp.Connection('host', username='me', password='pass', cnopts=cnopts): But apparently that leaves you open to man in the middle attacks. So I attempt to connect with: cnopts = pysftp.CnOpts(knownhosts='config/known

Writing to a file on SFTP server opened using pysftp “open” method is slow

陌路散爱 提交于 2019-12-08 08:55:52
问题 I have a piece of Python code that works, but is very slow to write a Dataframe directly to an SFTP location. I am using pysftp and pandas.to_csv() to achieve the task of reading an Excel file from a remote location, run a few simple transformations and write it over to an SFTP location. The code snippet is shared below which, takes 4 minutes 30 seconds precisely, to write 100 records to the SFTP location. An average Dataframe that I process has a maximum of 20 columns. def dataframe_sftp

Using python pysftp package, getting a “SSHException: Bad host key from server” error

删除回忆录丶 提交于 2019-12-08 05:45:24
问题 I am running Python 3 with the pysftp package, version 0.2.9. The following code I have is here. I am loading the hostkey correctly as shown by the line cnopts.hostkeys.keys() . import pysftp key_file_test = './path_to_key_file/key_file.pub' DOWNLOAD_UAT = { "USERNAME": "xxxxxxxx", "PASSWORD": "xxxxxxxx" } UAT_FTP_SITE = 'sftp-test.site.com' cnopts = pysftp.CnOpts() cnopts.hostkeys.load(key_file_test) cnopts.hostkeys.keys() '''['github.com', 'XXX.XX.XXX.XXX', 'sftp-test.site.com']''' srv =

Define transfer mode when trying to SFTP files using Python

孤者浪人 提交于 2019-12-08 04:37:28
问题 We are trying to transfer text files from a Linux server to a Windows server using a python script (which resides on the SFTP server). It is necessary for us to ensure the files are transferred using text mode. I don't see this possibility in pysftp . Is there any other Python library that supports this? 回答1: pysftp/Paramiko uses an SFTP protocol version 3. In the SFTP protocol version 3, there are no transfer modes. Or in other words, there is only the binary transfer mode. Even if pysftp

Python pysftp put_r does not work on Windows

夙愿已清 提交于 2019-12-08 04:16:04
问题 I'd like to upload multiple files from a Windows directory to an SFTP server using pysftp 0.2.8. I've read up the doc and it suggests to use put_d or put_r but both give me the following error: OSError: Invalid path: sftp_local_path = r'C:\Users\Swiss\some\path' sftp_remote_path = '/FTP/LPS Data/ATC/RAND/20191019_RAND/XML' with pysftp.Connection("xxx.xxx.xxx.xxx", username=myUsername, password=myPassword) as sftp: with sftp.cd(sftp_remote_path): sftp.put_r(sftp_local_path, sftp_remote_path)

Do not download empty folders while downloading from SFTP server using Python

亡梦爱人 提交于 2019-12-06 09:37:02
问题 I got a code to download files recursively in Python on this site. This code also downloads empty directories on server also. Please help me to modify this code so that it does not download empty directories from the server. Code I have (based on Python pysftp get_r from Linux works fine on Linux but not on Windows): import os import pysftp from stat import S_IMODE, S_ISDIR, S_ISREG cnopts = pysftp.CnOpts() cnopts.hostkeys = None sftp=pysftp.Connection('192.168.X.X', username='username'

pysftp — paramiko SSHException, Bad host key from server

若如初见. 提交于 2019-12-06 07:39:35
问题 I'm trying to connect to a remote host via pysftp : try: with pysftp.Connection(inventory[0], username='transit', private_key='~/.ssh/id_rsa.sftp', port=8055) as sftp: sftp.put('/home/me/test.file') except Exception, err: print sys.exc_info() print err However, I get a weird exception raised that I can't find much detail on. (<class 'paramiko.ssh_exception.SSHException'>, SSHException('Bad host key from server',), <traceback object at 0x7fa76269c5a8>) Bad host key from server I found a

Python Connect over HTTP proxy with pysftp

别说谁变了你拦得住时间么 提交于 2019-12-05 13:56:09
Currently, I am doing SFTP transfer using Python subprocess.POPEN and PuTTY psftp.exe . It is working, but not really clean nor transportable. I would like to reproduce the same behavior using Python pysftp, but I do not know where to input all the parameters. I have in PuTTY the following configuration: Server IP : 123.123.123.255 Server Port : 22 Connection Type : SSH AutoLogin UserName : MyUser Proxy type : HTTP Proxy Hostname : gw.proxy.fr Proxy port : 1234 Proxy Username : ProxyUser Proxy Password: ProxyPass How should I input all these parameters in pysftp so I can retrieve my files?

Do not download empty folders while downloading from SFTP server using Python

自作多情 提交于 2019-12-04 16:52:15
I got a code to download files recursively in Python on this site. This code also downloads empty directories on server also. Please help me to modify this code so that it does not download empty directories from the server. Code I have (based on Python pysftp get_r from Linux works fine on Linux but not on Windows ): import os import pysftp from stat import S_IMODE, S_ISDIR, S_ISREG cnopts = pysftp.CnOpts() cnopts.hostkeys = None sftp=pysftp.Connection('192.168.X.X', username='username',password='password',cnopts=cnopts) def get_r_portable(sftp, remotedir, localdir, preserve_mtime=False): for

pysftp — paramiko SSHException, Bad host key from server

我的未来我决定 提交于 2019-12-04 12:36:56
I'm trying to connect to a remote host via pysftp : try: with pysftp.Connection(inventory[0], username='transit', private_key='~/.ssh/id_rsa.sftp', port=8055) as sftp: sftp.put('/home/me/test.file') except Exception, err: print sys.exc_info() print err However, I get a weird exception raised that I can't find much detail on. (<class 'paramiko.ssh_exception.SSHException'>, SSHException('Bad host key from server',), <traceback object at 0x7fa76269c5a8>) Bad host key from server I found a related question that suggested I run ssh-keygen -R [host] to replace the key in my known_hosts file -- once