1

One of our suppliers has started sending reports where the filename is suffixed with the date of the export and I can't work out using PuTTY psftp how to always pick up the file regardless of the change in file name.

This works for the exact file
get "TBD_7dayExport_20190628.csv"

What I'm looking to do is something like:
get "TBD_7dayExport" %

My aim is to pick up a new dated file every day, import and rename to TBD_7dayExport.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

1

You can use mget command with a wildcard:

mget TBD_7dayExport_*.csv

But it won't allow you to rename the file to a fixed name. You would have to use some fancy batch file construct post-download. Something like this:
Removing part of filename with batch


Or use a more powerful SFTP client, which supports renaming files while transferring them.

For example with my WinSCP, you can do:

winscp.com /ini=nul /log=download.log /command ^
    "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xxxxxx...=""" ^
    "get TBD_7dayExport_*.csv TBD_7dayExport.csv" ^
    "exit"

WinSCP GUI can generate a script/batch-file template for you.

Some resources:


Another option is PuTTY pscp. It's less flexible than WinSCP, but can be just enough for your needs:

pscp username@example.com:TBD_7dayExport_*.csv TBD_7dayExport.csv
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 1
    Thanks, that did the trick! with the file on my local server I'll just run a variant of ren "TBD*.csv" "TBD.csv" to get it how I need it. – Dan Wateridge Jul 01 '19 at 11:29