A script to download, rename, and move files

Advertisement

EliF_Teepee
Joined:
Posts:
3
Location:
Illinois

A script to download, rename, and move files

Up until now, I have been been using WS_FTP but would like to switch to WinSCP.
I'm trying to convert this WS_FTP script into WinSCP:
"C:\Program Files (x86)\Ipswitch\WS_FTP 12\wsftppro.exe"
-s "sftp://USERNAME:PASSWORD@ftpus.pointclickcare.com/USERNAME/logs/*.sqb"
-d "local:C:\PccDataRelay\LogDownloads\"
-rename tx_[yyyy]-[mm]-[dd]_[hh]-[tt]-[ss]_[OnlyName].[OnlyExt]
-move "/USERNAME/logs/transferred/"
I've been able to convert it partially:
cd C:\PccDataRelay\TestDownloads

"C:\Program Files (x86)\WinSCP\winscp.com" /ini=nul /log=C:\PccDataRelay\AuditLogs\incremental_download.log /command ^
    "open sftp://USERNAME:PASSWORD@ftpus.pointclickcare.com/USERNAME/logs/ -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" ^
    "get /USERNAME/logs/*.sqb" ^
    "exit"
But that only downloads the files. How can I get it to rename and move the original files while also leaving them in-place on the FTP site?

Please note, I posted this question subsequently to StackOverflow as the issue is timely.

Thank you!

Reply with quote

Advertisement

ajay1993
Joined:
Posts:
1
Location:
United States

Get ftp files with timestamp + filename

Hello Martin sir,
I am trying to create automation script to download files from FTP server that are autogenerated every hour. I want to get filename as YYMMDD(File name) format (eg:19062400), which I am not able to get it. right now I am getting files with a name (00.190624)
My script is

open ftp://usrname:password.urlftp.com/
binary
get -neweronly "*.csv" "c:\PBI-files\*.%TIMESTAMP#yymmdd%.csv"
exit

Can you help me to get that format?
Thanks.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
31,790
Location:
Prague, Czechia

Re: Get ftp files with timestamp + filename

ajay1993 wrote:

Hello Martin sir,
I am trying to create automation script to download files from FTP server that are autogenerated every hour. I want to get filename as YYMMDD(File name) format (eg:19062400), which I am not able to get it. right now I am getting files with a name (00.190624)
Your question is not really clear, but I assume you want this:
get -neweronly "%TIMESTAMP#yymmdd%*.csv" "c:\PBI-files\" 
(the combination of -neweronly and %TIMESTAMP% is suspicious too, but hopefully you know what you are doing).

Reply with quote

Guest

Get ftp files with timestamp + filename

I have tried the code that you sent me, it throws me an error of "No matching files found 190625*"

My question was, I want to download multiple and only newly generated files from FTP server to the local directory with timestamp and filename according to this name format "(Timestamp)(filename)"
tried every other combination as follows:
[code]
winscp> get "%TIMESTAMP#yymmdd%*.csv" "c:\PBI-files\"
No file matching '190625*.csv' found.

get -neweronly "%TIMESTAMP#yymmdd%*.csv" "c:\PBI-files\"
No file matching '190625*.csv' found.

mget -neweronly "%TIMESTAMP#yymmdd%*.csv" "c:\PBI-files\"
No file matching '190625*.csv' found.
[code]

FTP directory has files names as 00.csv, 01.csv, 02.csv and so on.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
31,790
Location:
Prague, Czechia

Re: Get ftp files with timestamp + filename

Anonymous wrote:

FTP directory has files names as 00.csv, 01.csv, 02.csv and so on.
Earlier you wrote that "I want to get filename as YYMMDD(File name) format (eg:19062400),". Now you claim something entirely different.

Reply with quote

Advertisement

You can post new topics in this forum