I'd like to download many files (about 10000) from ftp-server. Names of the files are too long. I'd like to save them only with the date in names. For example: ABCDE201604120000-abcde.nc
I prefer to be 20160412.nc
Is it possible?

- 12,819
- 1
- 25
- 47

- 31
- 1
-
How do you download the files? Recursively, or do you use some bash scripting? – sauerburger Jan 17 '18 at 20:27
-
1wget -cr -np -S -P /home/MyFolderDownloads/ http:/NameOfTheSite.domain/AFolder/*.nc – Greta Georgieva Feb 04 '18 at 15:08
2 Answers
I am not sure if wget
provides similar functionality, nevertheless with curl
, one can profit from the relatively rich syntax it provides in order to specify the URL of interest. For example:
curl \
"https://ftp5.gwdg.de/pub/misc/openstreetmap/SOTMEU2014/[53-54].{mp3,mp4}" \
-o "file_#1.#2"
will download files 53.mp3, 53.mp4, 54.mp3, 54.mp4
. The output file is specified as file_#1.#2
- here, #1
is replaced by curl
with the value of the sequence [53-54]
corresponding to the file being downloaded. Similarly, #2
is replace with either mp3
or mp4
. Thus, e.g., 53.mp3
will be saved as file_53.mp3
.

- 12,819
- 1
- 25
- 47
ewcz's answer works fine if you can enumerate the file names as shown in the post. However, if the filenames are difficult to enumerate, for example, because the integers are sparsely populated, this solution would result in a lot of 404 Not Found
requests.
If this is the case, then it is probably better to download all the files recursively, as you have shown, and rename them afterwards. If the file names follow a fixed pattern, you can select the substring from the original name and use it as the new name. In the given example, the new file names start at position 5 and are 8 characters long. The following bash command renames all *.nc
files in the current directory.
for f in *.nc; do mv "$f" "${f:5:8}.nc" ; done
If the filenames do not follow a fix pattern and might vary in length, you can use more complex pattern substitution using sed
, see SO post for an example.

- 4,569
- 4
- 31
- 42