1

How would you go about getting a file from a SFTP server if the file has today date in the name of file?

I know the mget and get command is used to pull the file over, but I can't seem to find anything on pulling a file if it has a certain timestamp on it. I'm trying to write a bash script to pull this file down every morning but the name of the file changes everyday.

Example of the file I am trying to get pulled down from a sftp:

get arc.20201005.*

What I have tried:

get arc.$(date +%Y%m%d).*
get arc.(date +%Y%m%d).*
2
  • Does it have to be sftp or could you use scp? Commented Oct 5, 2020 at 15:11
  • Does your example filename of arc.20201005.* work as expected? Have you tried: get arc.$(date +%Y%m%d).\* ? I'm wondering if your local shell is expanding the *. Commented Oct 5, 2020 at 15:12

1 Answer 1

0

Figured out the answer. Since SFTP doesn't allow variables and has limited commands itself. I instead did the following.

#Set Variables

date=(date +%Y%m%d)

echo -e "mget /directorypath/arc.$date.*" | sftp username@IPaddress

The -e in the echo command is key to this working since it enables interpretation of backslash escapes.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.