A pretty quick and simple interface to paramiko SFTP

Overview

sftpretty

A pretty quick and simple interface to paramiko SFTP. Provides multi-threaded routines with progress notifications for reliable, asynchronous transfers. This is a Python3 optimized fork of pysftp with additional features & improvements.

  • Built-in retry decorator
  • Hash function for integrity checking
  • Improved local & remote directory mapping
  • Improved logging mechanism
  • More tests
  • Multi-threaded directory transfers
  • Progress notifications
  • Support for digests & kex connection options
  • Support for ED25519 & ECDSA keys
  • Support for private key passwords
  • Thread-safe connection manager

Example

from sftpretty import Connection


# Basic

with Connection('hostname', username='me', password='secret') as sftp:
    # Temporarily chdir to public/.
    with sftp.cd('public'):
        # Upload file to public/ on remote.
        sftp.put('/my/local/filename')
        # Download a remote file from public/.
        sftp.get('remote_file')


with Connection('hostname', private_key='~/.ssh/id_ed25519',
                            private_key_pass='secret') as sftp:
    # Upload local directory to remote_directory.
    sftp.put_d('/my/local', '/remote_directory')

    # Recursively download a remote_directory and save it to /tmp locally.
    sftp.get_r('remote_directory', '/tmp')


# Advanced

with Connection('hostname', username='me', password='secret') as sftp:
    # Upload local directory to remote_directory. On occurance of any
    # exception or child of, passed in the tuple, retry the operation.
    # Between each attempt increment a pause equal to backoff * delay.
    # Run a total of tries (six) times including the first attempt.
    sftp.put_d('/my/local', '/remote_directory',
               exceptions=(NoValidConnectionsError,
                           socket.timeout,
                           SSHException),
               tries=6, backoff=2, delay=1)


with Connection('hostname', private_key='~/.ssh/id_ed25519',
                            private_key_pass='secret') as sftp:
    # Recursively download a remote_directory and save it to /tmp locally.
    # Don't confirm files, useful in a scenario where the server removes
    # the remote file immediately after download. Preserve remote mtime on
    # local copy
    sftp.get_r('remote_directory', '/tmp', confirm=False,
               preserve_mtime=True)

Additional Information

Requirements

paramiko >= 1.17.0

Supports

Tested on Python 3.6, 3.7, 3.8, 3.9

https://travis-ci.org/byteskeptical/sftpretty.svg?branch=master
Comments
  • put_d() unexpected remote path handling and issue with absolute Windows paths

    put_d() unexpected remote path handling and issue with absolute Windows paths

    I found two issues with the put_d() function.

    1. It looks like it doesn't accept absolute Windows paths. I get the error:

    ValueError: 'C:\\Users\\johnm\\PycharmProjects\\project\\.other\\folder\\file' does not start with '\\'

    1. When I call put_d("local_folder", "folder"), I get the following error:

    File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\sftpretty\__init__.py", line 563, in put confirm=confirm, preserve_mtime=preserve_mtime) File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\sftpretty\__init__.py", line 554, in _put confirm=confirm) File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\paramiko\sftp_client.py", line 759, in put return self.putfo(fl, remotepath, file_size, callback, confirm) File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\paramiko\sftp_client.py", line 714, in putfo with self.file(remotepath, "wb") as fr: File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\paramiko\sftp_client.py", line 372, in open t, msg = self._request(CMD_OPEN, filename, imode, attrblock) File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\paramiko\sftp_client.py", line 822, in _request return self._read_response(num) File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\paramiko\sftp_client.py", line 874, in _read_response self._convert_status(msg) File "C:\Users\johnm\PycharmProjects\project\venv\lib\site-packages\paramiko\sftp_client.py", line 903, in _convert_status raise IOError(errno.ENOENT, text) FileNotFoundError: [Errno 2] Path not found.

    As I understand, the path it refers to is the remote path. When I debug it, in put_d(), the paths it creates are the following: image As you can see, the remotedir "folder/local_folder/file" is probably the issue. In my remote location, it creates the folder "folder". This of course makes sense as it successfully calls self.mkdir_p(remotedir) in line 599. Do you think this has to do with the location of the self.mkdir_p(remotedir) call? Should there be code that also creates the subfolders of the "local_folder" in the remote location(here the "folder/local_folder" subfolder)?

    Thank you for your time.

    bug 
    opened by Johnmaras 9
  • Add support to use a single channel for all commands. Some servers do…

    Add support to use a single channel for all commands. Some servers do…

    Certain SFTP server do not allow to open a channel for every command. The original pysftp used a single channel for all actions. I've added a flag to allow us to work in a similar way, while by default keeping the new behavior.

    Those servers will simply close the connection on the second command issued and it makes sftpretty not very useful with these old(er) SFTP servers.

    opened by erans 5
  • Typo in argument name - tires/tries

    Typo in argument name - tires/tries

    Hi,

    In sftpretty/init.py:716 there is a typo in the tries argument which causes the call to putfo() to raise an exception

    retry() got an unexpected keyword argument 'tires'

    bug 
    opened by Johnmaras 2
  • Fix potential `_channel` `UnboundLocalError`

    Fix potential `_channel` `UnboundLocalError`

    Sometimes when assigning to _channel, an exception can occur in SFTPClient.from_transport(). Because _channel doesn't exist if that happens, it causes a second exception when trying to call close() in the finally block. Assign to the variable outside the try block initially so that this exception can't happen in the future. Also make sure that _channel is not None before we try to close it to account for it being sometimes None.

    bug 
    opened by RobertCochran 1
  • calling basicConfig at this level for a library that should be embedded changes all dowstream logs

    calling basicConfig at this level for a library that should be embedded changes all dowstream logs

    Calling basicConfig on the top of the file for a library that is embedded into other projects can cause issue. I suggest you drop it completely specifically because there are no change to it other than setting the default level to INFO.

    https://github.com/byteskeptical/sftpretty/blob/ca8e2414ac156276059fcd091cc91e489d856e7d/sftpretty/init.py#L22

    In our case it added ":" to the start of every log line.

    enhancement 
    opened by erans 1
Releases(1.0.5)
Simple reverse backdoor utility, that uses sockets to communicate.

reverse_backdoor Simple reverse backdoor utility, that uses sockets to communicate. How to use Run rev_bd_listener.py using command below: $ python3 r

1 Dec 10, 2021
A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.

WARNING: This is from spyne's development branch. This version is not released yet! Latest stable release can be found in the 2_13 branch. If you like

1.1k Dec 23, 2022
A Project to resolve hostname and receive IP

hostname-resolver A Project to resolve hostname and receive IP Installation git clone https://github.com/ihapiw/hostname-resolver.git Head into the ho

iHapiW 5 Sep 12, 2022
Event-driven networking engine written in Python.

Twisted For information on changes in this release, see the NEWS file. What is this? Twisted is an event-based framework for internet applications, su

Twisted Matrix Labs 4.9k Jan 08, 2023
nettrace is a powerful tool to trace network packet and diagnose network problem inside kernel.

nettrace nettrace is is a powerful tool to trace network packet and diagnose network problem inside kernel on TencentOS. It make use of eBPF and BCC.

84 Jan 01, 2023
Tripwire monitors ports and icmp to send the admin a message if somebody is scanning a machine that shouldn't be touched

Tripwire monitors ports and icmp to send the admin a message if somebody is scanning a machine that shouldn't be touched

3 Apr 05, 2022
DataShare - Simple library for data sharing between scripts and public functions calling

DataShare - Simple library for data sharing between scripts and public functions calling. Installation. Install code, Delete LICENSE, README, readme.t

Ivan Perzhinsky. 1 Dec 17, 2021
Openconnect VPN RPi Gateway

Openconnect-VPN-RPi-Gateway See the blog (Chinese) for how to build an Openconne

Zhongze Tang 2 Jan 30, 2022
Home Assistant integration for MyEnergi devices

myenergi for Home Assistant myenergi custom component for Home Assistant This is a very early release, will add more documentations soon! This compone

Johan Isacsson 70 Dec 18, 2022
Eclipse zenoh Python API

Eclipse zenoh Python API Eclipse zenoh is an extremely efficient and fault-tolerant Named Data Networking (NDN) protocol that is able to scale down to

26 Jan 05, 2023
It's a little project for change MAC address, for ethical hacking purposes

MACChangerPy It's a small project for MAC address change, for ethical hacking purposes, don't use it for bad purposes, any infringement will be your r

Erick Adriano Nunes da Silva 1 Mar 11, 2022
Desktop application for checking sites connection in a background mode

Site connectivity checker Desktop application for checking site connection in a background mode by sending ICMP messages. Problem and solution Usually

Karina Singatullina 26 Dec 19, 2022
Timeouts for popular Python packages

Python Timeouts An unresponsive service can be worse than a down one. It can tie up your entire system if not handled properly. All network requests s

Andrew Kane 11 Nov 22, 2022
A Cheap Flight Alert program sends you a SMS to notify cheap flights in next 8 months.

Flight Dealer A Cheap Flight Alert program sends you a SMS to notify cheap flights (return trips) in next 6 months. Installing Download the Python 3 i

Aytaç Kaşoğlu 2 Feb 10, 2022
Public HTTPS access to Home Assistant with Dataplicity service

Custom component for public HTTPS access to Home Assistant with Dataplicity service. Should work on any Linux PC or ARM, not only Raspberry as Dataplicity service said. Don't work on Windows.

Alex X 70 Oct 03, 2022
A light-weight open-source project CLI utility for showing services running on ports in a host

Portable Port Scanner (ppscanner) Portable Port Scanner (ppscanner) is a light-weight open-source CLI utility that leverages on nmap to make quick and

1 Oct 30, 2021
Ipscanner - A simple threaded IP-Scanner written in python3 that can monitor local IP's in your network

IPScanner 🔬 A simple threaded IP-Scanner written in python3 that can monitor lo

4 Dec 12, 2022
MoreIP 一款基于Python的面向 MacOS/Linux 用户用于查询IP/域名信息的日常渗透小工具

MoreIP 一款基于Python的面向 MacOS/Linux 用户用于查询IP/域名信息的日常渗透小工具

xq17 9 Sep 21, 2022
The sequel to SquidNet. It has many of the previous features that were in the original script, however a lot of the functions that do not serve much functionality have been removed.

SquidNet2 The sequel to SquidNet. It has many of the previous features that were in the original script, however a lot of the functions that do not se

DrSquidX 5 Mar 25, 2022
A non-custodial oracle and escrow system for the lightning network. Make LN contracts more expressive.

Hodl contracts A non-custodial oracle and escrow system for the lightning network. Make LN contracts more expressive. If you fire it up, be aware: (1)

31 Nov 30, 2022