Home > Software engineering >  CURL SFTP - How to preserve the last modified date while downloading
CURL SFTP - How to preserve the last modified date while downloading

Time:03-24

I'm trying to download a file from another server but I also need to get the last modified date or the last timestamp of the file. I use curl sftp so that I don't have to enter my password every time I run it and I'm also going to run the curl command in perl program.

In SFTP I can preserve it by doing this command: get -p filename.txt

In my curl command, this is what I did:

curl -v -R -u user:userpass sftp://ip.add.re.ss:port/host/path/name/filename.txt > filename.txt 

But whenever I run this command, the timestamp is always updated.

Can someone help me to download the file and preserve the last modified date and time?

CodePudding user response:

-R doesn't work with > it requires -o

curl -R -o filename.txt -u user:userpass sftp://ip.add.re.ss:port/host/path/name/filename.txt

when you use > that's not really a command for curl, it's a command for your shell, it tells your shell to save curl's output to a file, and your shell doesn't understand -R. but -o tells curl to save the output to a file instead of printing the file, and curl understands -R

  • Related