Teja Goud Kandula
Teja Goud Kandula

Reputation: 1574

How to rename a downloaded file from within the WinSCP script?

I have WinSCP script that downloads a file from the SFTP server to the local machine. How can I rename the file from within the WinSCP script?

The script is being run from Windows machine.

The WinSCP script:

option batch off 
option confirm off 
open sftp://username:password@servername -hostkey=""
option transfer binary
get -latest "oldname.csv" c:\localfolder 
mv c:\localfolder\oldname.csv latestname.csv
exit

I tried renaming using the commands:

rename InitialFileName FinalFileName

then tried using:

mv InitialFileName FinalFileName

But the script is throwing the error:

File not found, Language: en 

Tried stuff from this blog

Upvotes: 4

Views: 1657

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202168

If you want to download the file to a different name, specify the new name directly in the get command:

get "oldname.csv" c:\localfolder\latestname.csv

(Note that when downloading one specific file, the -latest switch is pointless. The latest file out of one file[s] is that one file.)

Upvotes: 4

Related Questions