pysftp

pysftp: How to update last modified date

只谈情不闲聊 提交于 2020-08-26 06:58:10
问题 I am trying to move a certain file to another directory after doing some process over it. Moving the file was easy using Connection.rename import pysftp conn = pysftp.Connection(host = 'host', username = 'user', password = 'password') remote_src = '/dir1/file1.csv' remote_dest = '/dir2/archive_file1.csv' conn.rename(remote_src, remote_dest) conn.close() But the LastModified date remains same as of original file. Is there a way to update the LastModified date to current date while renaming?

“No hostkey for host ***** found” when connecting to SFTP server with pysftp using private key

我的未来我决定 提交于 2020-07-15 05:43:11
问题 So I am having many issues connecting to a remote server via SFTP. I have tried the normal way like below. sftp = pysftp.Connection(host='Host',username='username',password='passwd',private_key=".ppk") Which did not work. I got the following error: SSHException: No hostkey for host ***** found. I then tried the following: cnopts = pysftp.CnOpts() cnopts.hostkeys = None s = pysftp.Connection(host='host', username='user', password='password', cnopts=cnopts) Which also did not work. I got the

Archive all files from one SFTP folder to another in Python

霸气de小男生 提交于 2020-07-07 15:54:26
问题 I was able to successfully upload the file from S3 to SFTP location using the below syntax as given by @Martin Prikryl [https://stackoverflow.com/questions/58719309/transfer-file-from-aws-s3-to-sftp-using-boto-3/58725127] with sftp.open('/sftp/path/filename', 'wb') as f: s3.download_fileobj('mybucket', 'mykey', f) I have a requirement to archive the previous file into the archive folder from the current folder before uploading the current dated file from S3 to SFTP I am trying to achieve

Archive all files from one SFTP folder to another in Python

丶灬走出姿态 提交于 2020-07-07 15:54:01
问题 I was able to successfully upload the file from S3 to SFTP location using the below syntax as given by @Martin Prikryl [https://stackoverflow.com/questions/58719309/transfer-file-from-aws-s3-to-sftp-using-boto-3/58725127] with sftp.open('/sftp/path/filename', 'wb') as f: s3.download_fileobj('mybucket', 'mykey', f) I have a requirement to archive the previous file into the archive folder from the current folder before uploading the current dated file from S3 to SFTP I am trying to achieve

Exe built with cx_Freeze shows error when containing pysftp import

主宰稳场 提交于 2020-06-28 09:38:11
问题 I am trying to compile an executable from a python script that uses pysftp. I'm using cx_Freeze to do that. Here is my code: Test.py import datetime import time import os import pysftp i = 0 while(i<10): tm = datetime.datetime.now() print (tm.strftime('%H:%M:%S')) time.sleep(1) i += 1 Here is the setup: setup.py from cx_Freeze import setup, Executable base = None executables = [Executable("Test.py", base=base)] packages = ["idna", "datetime", "time", "os", "pysftp"] options = { 'build_exe': {

Python pysftp download fails with “IOError: [Errno 21] Is a directory”

拟墨画扇 提交于 2020-06-26 19:46:06
问题 Here is my sample Python script where I want to download a file from SFTP server to my local. srv = pysftp.Connection(host=host, username=username, password=password, port=port, cnopts=connOption) with srv.cd(sftppath): data = srv.listdir() try: for infile in data: print infile srv.get(infile, destination, preserve_mtime=True) I can connect successfully and it lists all files in the folder. But when I use srv.get() to download to my desktop I get following error, IOError: [Errno 21] Is a

How to write a string to file on ftp with pysftp?

北战南征 提交于 2020-06-26 04:15:23
问题 I have a large xml file stored in a variable. I want to write it directly to an ftp using pysftp. I believe I need to use the pysftp.putfo and this needs a file like object. Here is a minimal example: from io import StringIO from pysftp import Connection, CnOpts cnopts = CnOpts() cnopts.hostkeys = None with Connection('localhost' ,username= 'admin' ,password = 'test' ,cnopts=cnopts ) as sftp: sftp.putfo(StringIO('xml string')) I get the following error: TypeError: Expected unicode or bytes,

pysftp library not working in AWS lambda layer

橙三吉。 提交于 2020-06-11 06:01:12
问题 I want to upload files to EC2 instance using pysftp library (Python script). So I have created small Python script which is using below line to connect pysftp.Connection( host=Constants.MY_HOST_NAME, username=Constants.MY_EC2_INSTANCE_USERNAME, private_key="./mypemfilelocation.pem", ) some code here ..... pysftp.put(file_to_be_upload, ec2_remote_file_path) This script will upload files from my local Windows machine to EC2 instance using .pem file and it works correctly. Now I want to do this

pysftp library not working in AWS lambda layer

浪子不回头ぞ 提交于 2020-06-11 05:58:10
问题 I want to upload files to EC2 instance using pysftp library (Python script). So I have created small Python script which is using below line to connect pysftp.Connection( host=Constants.MY_HOST_NAME, username=Constants.MY_EC2_INSTANCE_USERNAME, private_key="./mypemfilelocation.pem", ) some code here ..... pysftp.put(file_to_be_upload, ec2_remote_file_path) This script will upload files from my local Windows machine to EC2 instance using .pem file and it works correctly. Now I want to do this

Read CSV/Excel files from SFTP file, make some changes in those files using Pandas, and save back

痞子三分冷 提交于 2020-05-22 07:47:51
问题 I want to read some CSV/Excel files on a secure SFTP folder, make some changes (fixed changes in each file like remove column 2) in those files, upload them to a Postgre DB and also the upload them to a different SFTP path in Python What's the best way to this? I have made a connection to the SFTP using pysftp library and am reading the Excel: import pysftp import pandas as pd myHostname = "*****" myUsername = "****" myPassword = "***8" cnopts =pysftp.CnOpts() cnopts.hostkeys = None sftp