Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Get oldest file from SFTP server

mukundmore wrote:

Hi. I have a requirement where files can be uploaded to the SFTP server at any time. I need to download the oldest file (First In First Out) from the SFTP server and load it in the database. I am using WinSCP command line script for this. Can someone please help me out here? I saw that there is a way to get the latest file using command line but nothing for oldest. Appreciate the help. Thanks.

See the script for downloading the most recent file:
https://winscp.net/eng/docs/script_download_most_recent_file
And just remove the -Descending switch from the Sort-Object cmdlet.
jrp78

From what I could find, there isn't a way to do it with winscp script but it's possible in powershell according to martin. https://winscp.net/forum/viewtopic.php?t=14340

If powershell is not an option, I will give you some food for thought. I assume after you process a file you delete it or move it? If so, think about making a two folder setup(staging & pickup). A staging folder where all the files go initially then use script/batch on the file system to only place the oldest file in a "pickup" folder. Then WinSCP can take it from there.
mukundmore

Get oldest file from SFTP server

Hi. I have a requirement where files can be uploaded to the SFTP server at any time. I need to download the oldest file (First In First Out) from the SFTP server and load it in the database. I am using WinSCP command line script for this. Can someone please help me out here? I saw that there is a way to get the latest file using command line but nothing for oldest. Appreciate the help. Thanks.