sftpkit 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sftpkit/exceptions.py ADDED
@@ -0,0 +1,32 @@
1
+ """pysftp specific exceptions"""
2
+
3
+
4
+ class ConnectionException(Exception):
5
+ """Exception raised for connection problems
6
+
7
+ Attributes:
8
+ message -- explanation of the error
9
+ """
10
+
11
+ def __init__(self, host, port):
12
+ # Call the base class constructor with the parameters it needs
13
+ Exception.__init__(self, host, port)
14
+ self.message = 'Could not connect to host:port. %s:%s'
15
+
16
+
17
+ class CredentialException(Exception):
18
+ """Exception raised for credential problems
19
+
20
+ Attributes:
21
+ message -- explanation of the error
22
+ """
23
+
24
+ def __init__(self, message):
25
+ # Call the base class constructor with the parameters it needs
26
+ Exception.__init__(self, message)
27
+ self.message = message
28
+
29
+
30
+ class HostKeysException(Exception):
31
+ '''raised when a problem with HostKeys is encountered'''
32
+ pass
sftpkit/helpers.py ADDED
@@ -0,0 +1,224 @@
1
+ """functions and classes that support the Connection object"""
2
+
3
+ from contextlib import contextmanager
4
+ import ntpath
5
+ import posixpath
6
+ import os
7
+ from stat import S_IMODE, S_ISDIR, S_ISREG
8
+
9
+
10
+ def known_hosts():
11
+ '''return a proper path to ssh's known_host file for the user'''
12
+ return os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts'))
13
+
14
+
15
+ def st_mode_to_int(val):
16
+ '''SFTAttributes st_mode returns an stat type that shows more than what
17
+ can be set. Trim off those bits and convert to an int representation.
18
+ if you want an object that was `chmod 711` to return a value of 711, use
19
+ this function
20
+
21
+ :param int val: the value of an st_mode attr returned by SFTPAttributes
22
+
23
+ :returns int: integer representation of octal mode
24
+
25
+ '''
26
+ return int(str(oct(S_IMODE(val)))[-3:])
27
+
28
+
29
+ class WTCallbacks(object):
30
+ '''an object to house the callbacks, used internally'''
31
+ def __init__(self):
32
+ '''set instance vars'''
33
+ self._flist = []
34
+ self._dlist = []
35
+ self._ulist = []
36
+
37
+ def file_cb(self, pathname):
38
+ '''called for regular files, appends pathname to .flist
39
+
40
+ :param str pathname: file path
41
+ '''
42
+ self._flist.append(pathname)
43
+
44
+ def dir_cb(self, pathname):
45
+ '''called for directories, appends pathname to .dlist
46
+
47
+ :param str pathname: directory path
48
+ '''
49
+ self._dlist.append(pathname)
50
+
51
+ def unk_cb(self, pathname):
52
+ '''called for unknown file types, appends pathname to .ulist
53
+
54
+ :param str pathname: unknown entity path
55
+ '''
56
+ self._ulist.append(pathname)
57
+
58
+ @property
59
+ def flist(self):
60
+ '''return a sorted list of files currently traversed
61
+
62
+ :getter: returns the list
63
+ :setter: sets the list
64
+ :type: list
65
+ '''
66
+ return sorted(self._flist)
67
+
68
+ @flist.setter
69
+ def flist(self, val):
70
+ '''setter for _flist '''
71
+ self._flist = val
72
+
73
+ @property
74
+ def dlist(self):
75
+ '''return a sorted list of directories currently traversed
76
+
77
+ :getter: returns the list
78
+ :setter: sets the list
79
+ :type: list
80
+ '''
81
+ return sorted(self._dlist)
82
+
83
+ @dlist.setter
84
+ def dlist(self, val):
85
+ '''setter for _dlist '''
86
+ self._dlist = val
87
+
88
+ @property
89
+ def ulist(self):
90
+ '''return a sorted list of unknown entities currently traversed
91
+
92
+ :getter: returns the list
93
+ :setter: sets the list
94
+ :type: list
95
+ '''
96
+ return sorted(self._ulist)
97
+
98
+ @ulist.setter
99
+ def ulist(self, val):
100
+ '''setter for _ulist '''
101
+ self._ulist = val
102
+
103
+
104
+ def path_advance(thepath, sep=os.sep):
105
+ '''generator to iterate over a file path forwards
106
+
107
+ :param str thepath: the path to navigate forwards
108
+ :param str sep: *Default: os.sep* - the path separator to use
109
+
110
+ :returns: (iter)able of strings
111
+
112
+ '''
113
+ # handle a direct path
114
+ pre = ''
115
+ if thepath[0] == sep:
116
+ pre = sep
117
+ curpath = ''
118
+ parts = thepath.split(sep)
119
+ if pre:
120
+ if parts[0]:
121
+ parts[0] = pre + parts[0]
122
+ else:
123
+ parts[1] = pre + parts[1]
124
+ for part in parts:
125
+ curpath = os.path.join(curpath, part)
126
+ if curpath:
127
+ yield curpath
128
+
129
+
130
+ def path_retreat(thepath, sep=os.sep):
131
+ '''generator to iterate over a file path in reverse
132
+
133
+ :param str thepath: the path to retreat over
134
+ :param str sep: *Default: os.sep* - the path separator to use
135
+
136
+ :returns: (iter)able of strings
137
+
138
+ '''
139
+ pre = ''
140
+ if thepath[0] == sep:
141
+ pre = sep
142
+ parts = thepath.split(sep)
143
+ while parts:
144
+ if os.path.join(*parts):
145
+ yield '%s%s' % (pre, os.path.join(*parts))
146
+ parts = parts[:-1]
147
+
148
+
149
+ def reparent(newparent, oldpath):
150
+ '''when copying or moving a directory structure, you need to re-parent the
151
+ oldpath. When using os.path.join to calculate this new path, the
152
+ appearance of a / root path at the beginning of oldpath, supplants the
153
+ newparent and we don't want this to happen, so we need to make the oldpath
154
+ root appear as a child of the newparent.
155
+
156
+ :param: str newparent: the new parent location for oldpath (target)
157
+ :param str oldpath: the path being adopted by newparent (source)
158
+
159
+ :returns: (str) resulting adoptive path
160
+ '''
161
+
162
+ if oldpath[0] in (posixpath.sep, ntpath.sep):
163
+ oldpath = '.' + oldpath
164
+ return os.path.join(newparent, oldpath)
165
+
166
+
167
+ def walktree(localpath, fcallback, dcallback, ucallback, recurse=True):
168
+ '''on the local file system, recursively descend, depth first, the
169
+ directory tree rooted at localpath, calling discreet callback functions
170
+ for each regular file, directory and unknown file type.
171
+
172
+ :param str localpath:
173
+ root of remote directory to descend, use '.' to start at
174
+ :attr:`.pwd`
175
+ :param callable fcallback:
176
+ callback function to invoke for a regular file.
177
+ (form: ``func(str)``)
178
+ :param callable dcallback:
179
+ callback function to invoke for a directory. (form: ``func(str)``)
180
+ :param callable ucallback:
181
+ callback function to invoke for an unknown file type.
182
+ (form: ``func(str)``)
183
+ :param bool recurse: *Default: True* - should it recurse
184
+
185
+ :returns: None
186
+
187
+ :raises: OSError, if localpath doesn't exist
188
+
189
+ '''
190
+
191
+ for entry in os.listdir(localpath):
192
+ pathname = os.path.join(localpath, entry)
193
+ mode = os.stat(pathname).st_mode
194
+ if S_ISDIR(mode):
195
+ # It's a directory, call the dcallback function
196
+ dcallback(pathname)
197
+ if recurse:
198
+ # now, recurse into it
199
+ walktree(pathname, fcallback, dcallback, ucallback)
200
+ elif S_ISREG(mode):
201
+ # It's a file, call the fcallback function
202
+ fcallback(pathname)
203
+ else:
204
+ # Unknown file type
205
+ ucallback(pathname)
206
+
207
+
208
+ @contextmanager
209
+ def cd(localpath=None): # pylint:disable=c0103
210
+ """context manager that can change to a optionally specified local
211
+ directory and restores the old pwd on exit.
212
+
213
+ :param str|None localpath: *Default: None* -
214
+ local path to temporarily make the current directory
215
+ :returns: None
216
+ :raises: OSError, if local path doesn't exist
217
+ """
218
+ try:
219
+ original_path = os.getcwd()
220
+ if localpath is not None:
221
+ os.chdir(localpath)
222
+ yield
223
+ finally:
224
+ os.chdir(original_path)
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.5
2
+ Name: sftpkit
3
+ Version: 1.0.0
4
+ Summary: A maintained, drop-in successor to pysftp. Works with paramiko 4 and 5.
5
+ Project-URL: Source, https://github.com/voltarostudio/sftpkit
6
+ Project-URL: Issues, https://github.com/voltarostudio/sftpkit/issues
7
+ Author: Voltaro Studio
8
+ License-Expression: BSD-3-Clause
9
+ License-File: LICENSE
10
+ Keywords: file transfer,paramiko,pysftp,sftp,ssh
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Internet :: File Transfer Protocol (FTP)
16
+ Classifier: Topic :: System :: Networking
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: paramiko>=3.2
19
+ Description-Content-Type: text/markdown
20
+
21
+ # sftpkit
22
+
23
+ A maintained successor to [pysftp](https://pypi.org/project/pysftp/), with the same API.
24
+
25
+ pysftp 0.2.9 was released in 2016 and has not changed since. It fails on import with paramiko 4 and later:
26
+
27
+ ```
28
+ ImportError: cannot import name 'DSSKey' from 'paramiko'
29
+ ```
30
+
31
+ sftpkit is pysftp 0.2.9 with that fixed, along with the bugs listed below.
32
+
33
+ ## Switch from pysftp
34
+
35
+ ```bash
36
+ pip uninstall pysftp
37
+ pip install sftpkit
38
+ ```
39
+
40
+ Then change one line:
41
+
42
+ ```python
43
+ import sftpkit as pysftp
44
+ ```
45
+
46
+ The rest of your code stays the same:
47
+
48
+ ```python
49
+ with pysftp.Connection("example.com", username="deploy",
50
+ private_key="~/.ssh/id_ed25519") as sftp:
51
+ sftp.put("report.csv", "/uploads/report.csv")
52
+ ```
53
+
54
+ ## Differences from pysftp 0.2.9
55
+
56
+ - Works with paramiko 3.2 through 5.x.
57
+ - Loads Ed25519 and ECDSA private keys. pysftp tried only RSA, then DSA.
58
+ - Checks a server on a port other than 22 against its `[host]:port` entry in `known_hosts`, the form OpenSSH writes.
59
+ - When `private_key` is not given, tries `~/.ssh/id_ed25519` and `~/.ssh/id_ecdsa` after pysftp's `id_rsa` and `id_dsa`.
60
+ - `get_r` creates the local folder when it does not exist.
61
+ - A failed connection raises only its own error. pysftp also raised `AttributeError: 'Connection' object has no attribute '_sftp_live'` while cleaning up.
62
+
63
+ Every public name, method, argument and default of pysftp 0.2.9 is kept, and the exception types are the same. A test checks this against the original source on every change.
64
+
65
+ Host keys are checked as in pysftp: a server must be in your `known_hosts`, unless you set `cnopts.hostkeys = None`.
66
+
67
+ ## Requirements
68
+
69
+ Python 3.10 or later, and paramiko 3.2 or later.
70
+
71
+ ## Credit
72
+
73
+ sftpkit began as pysftp 0.2.9 by Dundee Media & Technology, Inc, under the BSD 3-Clause licence. The first commit in this repository is that release, unchanged, so each of our changes can be read in the history.
74
+
75
+ ## Licence
76
+
77
+ BSD 3-Clause. See [LICENSE](LICENSE).
@@ -0,0 +1,7 @@
1
+ sftpkit/__init__.py,sha256=xzA8GdUO66JSgz8IUVryjyBQRFykEvAbbjG5hsLMhf8,38140
2
+ sftpkit/exceptions.py,sha256=H2QRTWLMrp6iffqRI6NK1g7TOM50D-vvVDIB1i-DGoY,852
3
+ sftpkit/helpers.py,sha256=f7F1SVliMC73QxMgFUkhUOP3I8AbHtrOcqJoZGnCl5k,6441
4
+ sftpkit-1.0.0.dist-info/METADATA,sha256=a-2uPmwpGZYpfIo_hRSBp2NnvBMI-WOD9GdVo-HW4uo,2734
5
+ sftpkit-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
6
+ sftpkit-1.0.0.dist-info/licenses/LICENSE,sha256=FzM0S7Zo1T04XZZY5Qr0PV83AZoK59H_y3VgHZZF2HQ,1721
7
+ sftpkit-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,31 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Voltaro Studio
4
+ Copyright (c) 2014, Dundee Media & Technology, Inc
5
+ All rights reserved.
6
+
7
+ sftpkit began as pysftp 0.2.9 by Dundee Media & Technology, Inc; its notice
8
+ and conditions below apply to the whole work.
9
+
10
+ Redistribution and use in source and binary forms, with or without modification,
11
+ are permitted provided that the following conditions are met:
12
+
13
+ * Redistributions of source code must retain the above copyright notice,
14
+ this list of conditions and the following disclaimer.
15
+ * Redistributions in binary form must reproduce the above copyright notice,
16
+ this list of conditions and the following disclaimer in the documentation
17
+ and/or other materials provided with the distribution.
18
+ * Neither the name of the Dundee Media & Technology, Inc nor the names of
19
+ its contributors may be used to endorse or promote products derived from
20
+ this software without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.