I create daily reports and send them using the FTP function in TOAD. I current overwrite the previous file, or add each day’s new report to their folder. I was asked if it were possible to only have the 5 most current reports in their folder. For example, if I ran the report today, Friday. In their folder, they would want to see today’s most current report plus Monday thru Thursday’s reports of this week.
I see there is a mask function for last week, but I don’t think that will capture this week’s reports. There is also a custom date, but I do not want to go in every day and modify the date range.
Does anyone have any ideas if this can be done or how to do it?
Masks intended to use with download and upload operations. From the other hand, it seems that you need the ability to delete some files in the remote directory. I don’t think it is possible to accomplish with Automation Ftp activity.
You might look into automating with WinSCP as a solution. Its batch mode works pretty well, although I haven’t solved this specific problem before. PowerShell is also pretty good for certain things like this. Something like the following might help (probably screwed up the syntax somewhere, might need a foreach after the second pipe).
get-childitem “C:\files” | where {$_.LastModifiedDate -gt (get-date).add-days(-7)} | cp “C:\sftp_these_files”
I also recomend WinSCP. in batch mode you can specify age of the file in days or hours. In your case < 6d would grab only the last 5 days. In order to delete files on a remote FTP (not your FTP site but their FTP site) you have to have the right permissions granted to you. I’ll have to check and see if WinSCP can delete with the file age parameter.
Never tried this with WinSCP but rm fileNameyyyymmdd.xtn would delete the remote file if you have permission, so rm fileName*.xtn >5d might work. i have used the <24h with get and file name mask to download the only files created in the last day. Never tried it with delete. You can also specify fileName*.* <yyyy-mm-dd (i.e. 2015-06-01 for files prior to June). In Toad automation you can call WinSCP with the run program step and pass the command line arguments which can inlcude a date variable or you can call a batch file (.bat) to do all of it.