fileshiftlib 0.0.1__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.
@@ -0,0 +1,3 @@
1
+ from .fileshift import SFTP
2
+
3
+ __all__ = ["SFTP"]
@@ -0,0 +1,7 @@
1
+ from .fileshift import SFTP
2
+
3
+ def main():
4
+ print("SFTP client Python package that uses paramiko library.")
5
+
6
+ if __name__ == "__main__":
7
+ main()
@@ -0,0 +1,135 @@
1
+ from dataclasses import dataclass
2
+ import logging
3
+ import paramiko
4
+
5
+
6
+ class SFTP(object):
7
+ @dataclass
8
+ class Configuration:
9
+ host: str = None
10
+ port: int = None
11
+ username: str = None
12
+ password: str = None
13
+
14
+ def __init__(self, host: str, username: str, password: str, port: int = 22) -> None:
15
+ """
16
+ Initializes the SFTP client with the given configuration and authenticates.
17
+
18
+ Args:
19
+ host (str): The hostname of the SFTP server.
20
+ username (str): The username for authentication.
21
+ password (str): The password for authentication.
22
+ port (int, optional): The port number of the SFTP server. Defaults to 22.
23
+ """
24
+ # Init logging
25
+ self.__logger = logging.getLogger(name=__name__)
26
+ self.__logger.setLevel(level=logging.INFO)
27
+ handler = logging.StreamHandler()
28
+ self.__logger.addHandler(handler)
29
+
30
+ # Credentials/configuration
31
+ self.sftp_client: paramiko.sftp_client.SFTPClient = None
32
+ self.__transport: paramiko.transport.Transport = None
33
+
34
+ port = 22 if port is None else port
35
+ self.__configuration = self.Configuration(host=host,
36
+ port=port,
37
+ username=username,
38
+ password=password)
39
+
40
+ # Authenticate
41
+ self.__transport, self.sftp_client = self.auth()
42
+
43
+ def __del__(self) -> None:
44
+ """
45
+ Destructor to clean up the SFTP client and close the transport session.
46
+ """
47
+ self.__logger.info(msg="Closes session")
48
+
49
+ self.__transport.close()
50
+ self.sftp_client.close()
51
+
52
+ def auth(self) -> tuple:
53
+ """
54
+ Authenticates with the SFTP server and initializes the SFTP client.
55
+
56
+ Returns:
57
+ tuple: A tuple containing the transport and SFTP client objects.
58
+ """
59
+ self.__logger.info(msg="Opens session")
60
+
61
+ # Connect
62
+ transport = paramiko.Transport((self.__configuration.host, self.__configuration.port))
63
+ transport.connect(username=self.__configuration.username, password=self.__configuration.password)
64
+ sftp_client = paramiko.SFTPClient.from_transport(transport)
65
+
66
+ return transport, sftp_client
67
+
68
+ def list_dir(self, path: str = ".") -> list:
69
+ """
70
+ Lists the names of the contents in the specified folder on the SFTP server.
71
+
72
+ Args:
73
+ path (str, optional): The path to the folder on the SFTP server. Defaults to the current directory.
74
+
75
+ Returns:
76
+ list: A list of names of the contents in the specified folder.
77
+ """
78
+ self.__logger.info(msg="Lists the names of the contents in the specified folder")
79
+ self.__logger.info(msg=path)
80
+
81
+ return self.sftp_client.listdir(path)
82
+
83
+ def change_dir(self, path: str = ".") -> None:
84
+ """
85
+ Changes the current working directory on the SFTP server.
86
+
87
+ Args:
88
+ path (str, optional): The path to the folder to change to on the SFTP server. Defaults to the current directory.
89
+ """
90
+ self.__logger.info(msg="Changes the current working directory")
91
+ self.__logger.info(msg=path)
92
+
93
+ self.sftp_client.chdir(path)
94
+
95
+ def delete_file(self, filename: str) -> None:
96
+ """
97
+ Deletes a file on the SFTP server.
98
+
99
+ Args:
100
+ filename (str): The name of the file to delete on the SFTP server.
101
+ """
102
+ self.__logger.info(msg="Deletes a file")
103
+ self.__logger.info(msg=filename)
104
+
105
+ self.sftp_client.remove(filename)
106
+
107
+ def download_file(self, remote_path: str, local_path: str) -> None:
108
+ """
109
+ Downloads a file from the SFTP server to the local machine.
110
+
111
+ Args:
112
+ remote_path (str): The path to the file on the SFTP server.
113
+ local_path (str): The path on the local machine where the file will be saved.
114
+ """
115
+ self.__logger.info(msg="Downloads a file from the SFTP server to the local machine")
116
+ self.__logger.info(msg=remote_path)
117
+ self.__logger.info(msg=local_path)
118
+
119
+ self.sftp_client.get(remote_path, local_path)
120
+
121
+ def upload_file(self, local_path: str, remote_path: str) -> None:
122
+ """
123
+ Uploads a file from the local machine to the SFTP server.
124
+
125
+ Args:
126
+ local_path (str): The path to the file on the local machine.
127
+ remote_path (str): The path on the SFTP server where the file will be saved.
128
+ """
129
+ self.__logger.info(msg="Uploads a file from the local machine to the SFTP")
130
+ self.__logger.info(msg=local_path)
131
+ self.__logger.info(msg=remote_path)
132
+
133
+ self.sftp_client.put(local_path, remote_path)
134
+
135
+ # eom
@@ -0,0 +1,94 @@
1
+ Metadata-Version: 2.4
2
+ Name: fileshiftlib
3
+ Version: 0.0.1
4
+ Summary: SFTP client!
5
+ Author-email: Paulo Portela <portela.paulo@gmail.com>
6
+ Maintainer-email: Paulo Portela <portela.paulo@gmail.com>
7
+ License-Expression: BSD-3-Clause
8
+ Project-URL: Homepage, https://github.com/aghuttun/fileshiftlib
9
+ Project-URL: Documentation, https://github.com/aghuttun/fileshiftlib/blob/main/README.md
10
+ Keywords: SFTP,Python,FTP,File Transfer
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: Implementation :: CPython
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: MacOS :: MacOS X
18
+ Requires-Python: >=3.13
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE.txt
21
+ Requires-Dist: paramiko>=3.0
22
+ Dynamic: license-file
23
+
24
+ # fileshiftlib
25
+
26
+ * [Description](#package-description)
27
+ * [Usage](#usage)
28
+ * [Installation](#installation)
29
+ * [License](#license)
30
+
31
+ ## Package Description
32
+
33
+ SFTP client Python package that uses [paramiko](https://pypi.org/project/paramiko/) library.
34
+
35
+ ## Usage
36
+
37
+ * [fileshiftlib](#fileshiftlib)
38
+
39
+ from a script:
40
+
41
+ ```python
42
+ import fileshiftlib
43
+ import logging
44
+
45
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
46
+
47
+ host = "localhost"
48
+ username = "123..."
49
+ password = "xxxx"
50
+ port = 22
51
+
52
+ # Initialize SFTP client
53
+ sftp = fileshiftlib.SFTP(host=host,
54
+ username=username,
55
+ password=password,
56
+ port=port)
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ * [fileshiftlib](#fileshiftlib)
62
+
63
+ Install python and pip if you have not already.
64
+
65
+ Then run:
66
+
67
+ ```bash
68
+ pip3 install pip --upgrade
69
+ pip3 install wheel
70
+ ```
71
+
72
+ For production:
73
+
74
+ ```bash
75
+ pip3 install fileshiftlib
76
+ ```
77
+
78
+ This will install the package and all of it's python dependencies.
79
+
80
+ If you want to install the project for development:
81
+
82
+ ```bash
83
+ git clone https://github.com/aghuttun/fileshiftlib.git
84
+ cd fileshiftlib
85
+ pip3 install -e .[dev]
86
+ ```
87
+
88
+ To test the development package: [Testing](#testing)
89
+
90
+ ## License
91
+
92
+ * [fileshiftlib](#fileshiftlib)
93
+
94
+ BSD License (see license file)
@@ -0,0 +1,8 @@
1
+ fileshiftlib/__init__.py,sha256=i9ClLZboHHUkM_4-TAp8WjxWn25joiLKmx-XoZzSug8,51
2
+ fileshiftlib/__main__.py,sha256=usjroUuPKq8yvL8KYJC_T9QPqbwWGVFBv1SUl-pmI1g,155
3
+ fileshiftlib/fileshift.py,sha256=suEIK-ZC9WY-kilQTQDdf8Sswvecx_MiFtdRaAl3kiI,4951
4
+ fileshiftlib-0.0.1.dist-info/licenses/LICENSE.txt,sha256=18KXUvbHORa48k6axcyPfIqUhl6vo3nQglZA8jSRHVA,1473
5
+ fileshiftlib-0.0.1.dist-info/METADATA,sha256=7LEx5VYaNf2dhpt0l90YvbYU8fC7uodfBc83pBxeKb0,2301
6
+ fileshiftlib-0.0.1.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
7
+ fileshiftlib-0.0.1.dist-info/top_level.txt,sha256=HUWlxFzXEsJRxW5PRN_2rxyjiuPjQQTlY26h_x8kFFI,13
8
+ fileshiftlib-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.3.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,11 @@
1
+ Copyright 2025 Paulo Portela
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ fileshiftlib