Comments (7)
I think this could be added, if there is a need for it. It is not trivial though, because of the way the SCP protocol works: we request something (usually files or folders, potentially with wildcards) and then the server sends multiple commands back (which can be a file, or file metadata, or recursing in a subdirectory). So we'd need to keep track of the fact that we expect a single file and fail if the server pushes multiple.
Or maybe something more generic than a file object could be passed in, an interface that could get files with their path and metadata.
class FileReceiver(object):
def open_file(self, pathname, atime, mtime, size):
"""Returns a file descriptor on which the server will write this file.
"""
raise NotImplementedError
from scp.py.
An admittedly weird but theoretically working workaround for a recursive/dir scp would be to just put the resulting files in a tarfile object. If a parameter is added to a getfo() method like single_file = True
, it'd be treated as a single object put into an io.BytesIO() object (for python 3; I think this is an io.StringIO() object in python 2?). If single_file
is false, we can specify that we are expecting multiple files and these can either be accessed directly with tarfile methods or a compat layer (iterator of filenames, etc.) could be implemented.
from scp.py.
I don't think anybody expects this to happen. This library has nothing to do with TAR files.
from scp.py.
Inherently? No. But tarfile is in stdlib and provides a native stream-based interface/object for a container of files, which is what you'd need for handling a return of multiple files from the remote (specifically addressing the issues presented in #94 (comment)) instead of just raising an exception if more than one file is returned.
from scp.py.
I would rather raise an exception than do something completely different and unexpected.
from scp.py.
just came across this "lack" on scp.py. Here is the use-case:
we do want to update a file on an appliance that only supports SCP. As the file contains sensitive data, ideal we would like to only have a copy "in-memory", hence a scp.getfo for a single file makes sense. I would also vote to raise an exception if more than one file is sent by the request.
Example:
[...]
scp.getfo -> to retrieve the file in-memory
[update the content]
scp.putfo -> send back to SCP server
from scp.py.
I thought I'd try to add this. A single file can be read into an object of io.BytesIO
, or of a new subclass that can additionally hold metadata. As for the multiple-file cases, getfo()
could return a data structure containing lists of such file-like objects, with dictionaries for directories and their contents. However, wouldn't it be more streamlined and consistent to limit the scope of getfo()
to only single-file usage, just like putfo()
?
from scp.py.
Related Issues (20)
- scp doesn't check the exit code of the remote command (needed for Windows) HOT 1
- Support streams HOT 3
- exlude some files HOT 1
- remote delete Files after successfully download HOT 1
- Freebsd (Juniper Junos) not happy with extra space in Secure Copy get HOT 2
- Creating directories HOT 1
- Transfer directory HOT 4
- paramiko.ssh_exception.SSHException: Incompatible ssh peer (no acceptable host key) on all tests HOT 1
- Get data into file-like object - getfo HOT 1
- scp does not work with pathlib.PurePath HOT 1
- How do I download multiple files at the same time?
- Permission denied with .put() HOT 10
- Remote wildcard does not work HOT 2
- File not closed in case SocketTimeout occured
- Pass progress callback when calling get/put methods on SCPClient HOT 3
- Retrieve scp errors HOT 6
- add support when both source and target are from remote locations (not necessary the same server)
- Add support for get() to keep downloaded file in memory via a BytesIO object as the "local_file" HOT 1
- Request for enhancement support to download all regular file in case of there is non-regular file under one folder HOT 3
- Using a trailing forward slash in Windows causes problems
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scp.py.