I need to download a series of files over ftp on a command line. The server I am downloading from has a folder structure which is like so:


I know that it is possible to use mget to download multiple files and the potential of wildcards but I need to apply a bit of search criteria to the download.

The search criteria is that from a given directory I am in when connected from the server I want to search all sub directories from that folder and look for files and apply a search criteria which looks for the following strings:


The string criteria will look for files which match this range of numbers. How can I go about doing this?

If a solution is only possible through programming I am quite proficient with python so that won't be a problem in terms of finding an alternative.


I crafted this solution using bash code:

for i in /path/to/file1/*/*;
    if [[ ${i##*[[:alpha:]]} =~ [[:digit:]][[:digit:]][[:digit:]] ]]
         echo $(realpath "$i")

This matches the three digits (101, 102, 103..., 199) in the file name. Replace the echo command with your ftp command for each file matched. Please test with echo command and run when okay.

The path is important, as /path/to/file1/* won't search as it contains subdirectories with subdirectories, so the search path should be /path/to/file1/*/*. Please change accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.