11import builtins
22import copy
3+ import stat
4+
5+ import paramiko
36
47from datashuttle .utils import rclone , ssh
58
@@ -57,7 +60,7 @@ def setup_hostkeys(project):
5760 restore_mock_input (orig_builtin )
5861
5962 orig_getpass = copy .deepcopy (ssh .getpass .getpass )
60- ssh .getpass .getpass = lambda _ : "password"
63+ ssh .getpass .getpass = lambda _ : "password" # type: ignore
6164
6265 ssh .setup_ssh_key (project .cfg , log = False )
6366 ssh .getpass .getpass = orig_getpass
@@ -81,3 +84,37 @@ def build_docker_image(project):
8184 central_host_id = "localhost" ,
8285 central_host_username = "sshuser" ,
8386 )
87+
88+
89+ def sftp_recursive_file_search (sftp , path_ , all_filenames ):
90+ try :
91+ sftp .stat (path_ )
92+ except FileNotFoundError :
93+ return
94+
95+ for file_or_folder in sftp .listdir_attr (path_ ):
96+ if stat .S_ISDIR (file_or_folder .st_mode ):
97+ sftp_recursive_file_search (
98+ sftp ,
99+ path_ + "/" + file_or_folder .filename ,
100+ all_filenames ,
101+ )
102+ else :
103+ all_filenames .append (path_ + "/" + file_or_folder .filename )
104+
105+
106+ def recursive_search_central (project ):
107+ """ """
108+ with paramiko .SSHClient () as client :
109+ ssh .connect_client (client , project .cfg )
110+
111+ sftp = client .open_sftp ()
112+
113+ all_filenames = []
114+
115+ sftp_recursive_file_search (
116+ sftp ,
117+ (project .cfg ["central_path" ] / "rawdata" ).as_posix (),
118+ all_filenames ,
119+ )
120+ return all_filenames
0 commit comments