# ftp by mask



## d2e8k (Mar 21, 2016)

Good time of day!
There is server from which I need download files. Files have names according to date and time (e.g. 20160320110002.txt, 20160320210218.txt, ...) Every evening I should download files for current  date using .netrc.   .netrc contains:

```
machine хх.ххх.ххх.ххх 
login хххххх 
password хххххх 
macdef init 
lcd local-path 
cd path-to-files 
prompt off 
binary hash 
mget 201* 
exit
```
I wish that line mget 201*  has mask with current date - 20160321* (not 201*), because now I download all files and that is not rationally (too many files). Could somebody suggest ,  how mask can be used in .netrc.

Thanks in advance


----------



## Juha Nurmela (Mar 23, 2016)

You could use the .netrc only for login information and run something like

```
#!/bin/sh

ymd=`date +%Y%m%d` && cd local_directory && ftp "remote:/remote_directory/${ymd}*.txt"
```

Juha


----------



## d2e8k (Mar 25, 2016)

Great! It is exatly what I need. 
Juha, a lot of thanks.


----------



## Juha Nurmela (Mar 26, 2016)

There's a nice flag, -v-1d in date(1). You could wait until midnight and fetch the yesterday's files. `date -v-1d +%Y%m%d`

Juha


----------



## d2e8k (Mar 27, 2016)

Just today I was searching such function and found it with using perl. 
But date -v-1d is more suitable for me.
Once more, MANY THANKS, Juha.


----------

