@@ -129,7 +129,16 @@ def run
129
129
if File . directory? datastore [ 'TARGETFILE' ]
130
130
print_status ( "Listing directory: #{ datastore [ 'TARGETFILE' ] } " )
131
131
132
- recurse_dir ( sftp , datastore [ 'TARGETFILE' ] )
132
+ sftp . dir . glob ( datastore [ 'TARGETFILE' ] , '**/*' ) do |entry |
133
+ # When we print the entry, we want to print the full path for each entry, so that further use of this module
134
+ # can set the TARGETFILE correctly to the full path of a target file. The longname will contain (along with
135
+ # permission, sizes and timestamps) a file/dir name but no path information. As we are using glob to
136
+ # recursively list the contents of all sub folders, we reconstitute the full path for every entry before
137
+ # printing it.
138
+ entry_full_path = File . join ( datastore [ 'TARGETFILE' ] , entry . name )
139
+
140
+ print_line ( entry . longname . gsub ( File . basename ( entry . name ) , entry_full_path ) )
141
+ end
133
142
else
134
143
print_status ( "Downloading file: #{ datastore [ 'TARGETFILE' ] } " )
135
144
@@ -150,19 +159,6 @@ def run
150
159
::Net ::SSH ::Authentication ::Methods ::Publickey . send ( :alias_method , :build_request , :orig_build_request )
151
160
end
152
161
153
- def recurse_dir ( sftp , base_path )
154
- sftp . dir . foreach ( base_path ) do |entry |
155
- entry_full_path = base_path . dup
156
- entry_full_path << '/' unless base_path . end_with? '/'
157
- entry_full_path << entry . name
158
- entry_full_path << '/' if entry . directory?
159
-
160
- print_line ( entry . longname . gsub ( entry . name , entry_full_path ) )
161
-
162
- recurse_dir ( sftp , entry_full_path ) if entry . directory?
163
- end
164
- end
165
-
166
162
def read_file ( sftp , file_path )
167
163
sftp . open ( file_path ) do |open_response |
168
164
if open_response . ok?
0 commit comments