Winscp Script to Rename a File to Append Timestamp


Based on a link from Stackoverflow by WinSCP author Martin Prikryl:
The put command accepts an optional second argument to specify a target name.
put localfile remotefile

http://stackoverflow.com/questions/41465186/batch-script-to-rename-file-with-timestamp-on-ftp-server-after-upload

Here is an example I used:

winscp.StandardInput.WriteLine(“put E:\\myfolder\\myfile.csv myfile” + DateTime.Now.ToString(“_MMddyyyy_HHmm”) + “.csv”);
The local file name is myfile.csv and the remote file name changed to
myfile_03202017_1413.csv

//Based on WinSCP site forum, Martin suggested: mv command should work as well
//winscp.StandardInput.WriteLine(“mv myfile.csv myfile”+ DateTime.Now.ToString(“_MMddyyyy_HHmm”) + “.csv”);

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s