Get oldest file from SFTP server

Advertisement

mukundmore
Joined:
Posts:
1

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.

Reply with quote

Advertisement

jrp78
Joined:
Posts:
22
Location:
SoVA

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.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

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.

Reply with quote

Advertisement

You can post new topics in this forum