brynq-sdk-ftp 2.0.2__tar.gz → 2.0.5__tar.gz
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.
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/PKG-INFO +1 -1
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp/sftp.py +16 -35
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp.egg-info/PKG-INFO +1 -1
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/setup.py +1 -1
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp/__init__.py +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp/ftps.py +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp.egg-info/not-zip-safe +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp.egg-info/requires.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/brynq_sdk_ftp.egg-info/top_level.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.5}/setup.cfg +0 -0
|
@@ -6,6 +6,7 @@ from paramiko.sftp_attr import SFTPAttributes
|
|
|
6
6
|
import pysftp
|
|
7
7
|
from typing import Union, List
|
|
8
8
|
from stat import S_ISREG
|
|
9
|
+
import os
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class SFTP(BrynQ):
|
|
@@ -26,16 +27,18 @@ class SFTP(BrynQ):
|
|
|
26
27
|
self.password = credentials['password']
|
|
27
28
|
self.cnopts = pysftp.CnOpts()
|
|
28
29
|
self.cnopts.hostkeys = None
|
|
29
|
-
self.private_key_path = None
|
|
30
|
-
self.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
self.
|
|
34
|
-
if credentials['private_key'] is not None:
|
|
35
|
-
self.private_key = RSAKey(file_obj=StringIO(credentials['private_key']))
|
|
30
|
+
self.private_key_path = credentials.get('private_key_password', None)
|
|
31
|
+
self.private_key_passphrase = credentials.get('private_key_password', None)
|
|
32
|
+
self.private_key = credentials.get('private_key', None)
|
|
33
|
+
if self.private_key:
|
|
34
|
+
self.private_key = RSAKey(file_obj=StringIO(credentials.get('private_key')), password=self.private_key_passphrase)
|
|
36
35
|
self.client = SSHClient()
|
|
37
36
|
self.client.set_missing_host_key_policy(AutoAddPolicy())
|
|
38
37
|
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
39
42
|
def upload_file(self, local_filepath, remote_filepath, confirm=True) -> SFTPAttributes:
|
|
40
43
|
"""
|
|
41
44
|
Upload a single file to a remote location. If there is no Private key
|
|
@@ -44,10 +47,7 @@ class SFTP(BrynQ):
|
|
|
44
47
|
:param confirm: If you want to confirm the upload
|
|
45
48
|
:return: status
|
|
46
49
|
"""
|
|
47
|
-
|
|
48
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
49
|
-
else:
|
|
50
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key)
|
|
50
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password, pkey=self.private_key, passphrase=self.private_key_passphrase)
|
|
51
51
|
sftp = self.client.open_sftp()
|
|
52
52
|
response = sftp.put(local_filepath, remote_filepath, confirm=confirm)
|
|
53
53
|
self.client.close()
|
|
@@ -60,14 +60,7 @@ class SFTP(BrynQ):
|
|
|
60
60
|
:param remote_filepath: The full path where you want to get the content from
|
|
61
61
|
:return: a list with files and folders in the given location
|
|
62
62
|
"""
|
|
63
|
-
|
|
64
|
-
if self.debug:
|
|
65
|
-
print('No private key')
|
|
66
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
67
|
-
else:
|
|
68
|
-
if self.debug:
|
|
69
|
-
print('Private key')
|
|
70
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key)
|
|
63
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
71
64
|
sftp = self.client.open_sftp()
|
|
72
65
|
sftp.chdir(remote_filepath)
|
|
73
66
|
list_files = sftp.listdir_attr()
|
|
@@ -84,10 +77,7 @@ class SFTP(BrynQ):
|
|
|
84
77
|
:param local_path: the path where the file needs to be downloaded to
|
|
85
78
|
:return: a file object
|
|
86
79
|
"""
|
|
87
|
-
|
|
88
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
89
|
-
else:
|
|
90
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key)
|
|
80
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
91
81
|
sftp = self.client.open_sftp()
|
|
92
82
|
sftp.get(remotepath=f'{remote_path}{remote_file}', localpath=f'{local_path}/{remote_file}')
|
|
93
83
|
self.client.close()
|
|
@@ -99,10 +89,7 @@ class SFTP(BrynQ):
|
|
|
99
89
|
:param new_dir_name: The name of the new folder
|
|
100
90
|
:return: a status if creating succeeded or not
|
|
101
91
|
"""
|
|
102
|
-
|
|
103
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
104
|
-
else:
|
|
105
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key)
|
|
92
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
106
93
|
sftp = self.client.open_sftp()
|
|
107
94
|
sftp.chdir(remote_path)
|
|
108
95
|
sftp.mkdir(new_dir_name)
|
|
@@ -114,10 +101,7 @@ class SFTP(BrynQ):
|
|
|
114
101
|
:param remote_file: the full path of the file that needs to be removed
|
|
115
102
|
:return: a status if deleting succeeded or not
|
|
116
103
|
"""
|
|
117
|
-
|
|
118
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
119
|
-
else:
|
|
120
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key)
|
|
104
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
121
105
|
sftp = self.client.open_sftp()
|
|
122
106
|
sftp.remove(remote_file)
|
|
123
107
|
self.client.close()
|
|
@@ -129,10 +113,7 @@ class SFTP(BrynQ):
|
|
|
129
113
|
:param new_file_path: the full path of the new location of the file
|
|
130
114
|
:return:
|
|
131
115
|
"""
|
|
132
|
-
|
|
133
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
|
|
134
|
-
else:
|
|
135
|
-
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key)
|
|
116
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
136
117
|
sftp = self.client.open_sftp()
|
|
137
118
|
sftp.rename(oldpath=old_file_path, newpath=new_file_path)
|
|
138
119
|
self.client.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|