To Sort Files Added to SFTP Server by Timestamp of Addition, Utilize the Following Function:
let list = connection.list({
path: ‘/Outbound Order Shipments’
});
Here ‘Outbound Order Shipments’ is the SFTP folder to which the files are added.
// Sort files by creation timestamp
list.sort((a, b) => new Date(a.lastModified).getTime() – new Date(b.lastModified).getTime());