brynq-sdk-ftp 2.0.2__tar.gz → 2.0.4__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.4}/PKG-INFO +1 -1
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp/sftp.py +14 -35
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp.egg-info/PKG-INFO +1 -1
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/setup.py +1 -1
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp/__init__.py +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp/ftps.py +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp.egg-info/not-zip-safe +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp.egg-info/requires.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/brynq_sdk_ftp.egg-info/top_level.txt +0 -0
- {brynq_sdk_ftp-2.0.2 → brynq_sdk_ftp-2.0.4}/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,16 @@ 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
|
-
self.private_key_path = credentials['private_key_path']
|
|
33
|
-
self.private_key_pass = credentials['private_key_password']
|
|
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 = RSAKey(file_obj=StringIO(credentials.get('private_key')), password=self.private_key_passphrase)
|
|
36
33
|
self.client = SSHClient()
|
|
37
34
|
self.client.set_missing_host_key_policy(AutoAddPolicy())
|
|
38
35
|
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
39
40
|
def upload_file(self, local_filepath, remote_filepath, confirm=True) -> SFTPAttributes:
|
|
40
41
|
"""
|
|
41
42
|
Upload a single file to a remote location. If there is no Private key
|
|
@@ -44,10 +45,7 @@ class SFTP(BrynQ):
|
|
|
44
45
|
:param confirm: If you want to confirm the upload
|
|
45
46
|
:return: status
|
|
46
47
|
"""
|
|
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)
|
|
48
|
+
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
49
|
sftp = self.client.open_sftp()
|
|
52
50
|
response = sftp.put(local_filepath, remote_filepath, confirm=confirm)
|
|
53
51
|
self.client.close()
|
|
@@ -60,14 +58,7 @@ class SFTP(BrynQ):
|
|
|
60
58
|
:param remote_filepath: The full path where you want to get the content from
|
|
61
59
|
:return: a list with files and folders in the given location
|
|
62
60
|
"""
|
|
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)
|
|
61
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
71
62
|
sftp = self.client.open_sftp()
|
|
72
63
|
sftp.chdir(remote_filepath)
|
|
73
64
|
list_files = sftp.listdir_attr()
|
|
@@ -84,10 +75,7 @@ class SFTP(BrynQ):
|
|
|
84
75
|
:param local_path: the path where the file needs to be downloaded to
|
|
85
76
|
:return: a file object
|
|
86
77
|
"""
|
|
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)
|
|
78
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
91
79
|
sftp = self.client.open_sftp()
|
|
92
80
|
sftp.get(remotepath=f'{remote_path}{remote_file}', localpath=f'{local_path}/{remote_file}')
|
|
93
81
|
self.client.close()
|
|
@@ -99,10 +87,7 @@ class SFTP(BrynQ):
|
|
|
99
87
|
:param new_dir_name: The name of the new folder
|
|
100
88
|
:return: a status if creating succeeded or not
|
|
101
89
|
"""
|
|
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)
|
|
90
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
106
91
|
sftp = self.client.open_sftp()
|
|
107
92
|
sftp.chdir(remote_path)
|
|
108
93
|
sftp.mkdir(new_dir_name)
|
|
@@ -114,10 +99,7 @@ class SFTP(BrynQ):
|
|
|
114
99
|
:param remote_file: the full path of the file that needs to be removed
|
|
115
100
|
:return: a status if deleting succeeded or not
|
|
116
101
|
"""
|
|
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)
|
|
102
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
121
103
|
sftp = self.client.open_sftp()
|
|
122
104
|
sftp.remove(remote_file)
|
|
123
105
|
self.client.close()
|
|
@@ -129,10 +111,7 @@ class SFTP(BrynQ):
|
|
|
129
111
|
:param new_file_path: the full path of the new location of the file
|
|
130
112
|
:return:
|
|
131
113
|
"""
|
|
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)
|
|
114
|
+
self.client.connect(hostname=self.host, port=self.port, username=self.username, pkey=self.private_key, password=self.password)
|
|
136
115
|
sftp = self.client.open_sftp()
|
|
137
116
|
sftp.rename(oldpath=old_file_path, newpath=new_file_path)
|
|
138
117
|
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
|