Topic "Download Newest File with VBA"

Author Message
BW
[View user's profile]

Joined: 2016-08-31
Posts: 1
Hello,
I'm able to download a specific file using the script below as described on this site:
----------------
Dim mySession As New Session

On Error Resume Next

Dim mySessionOptions As New SessionOptions
With mySessionOptions
.Protocol = Protocol_Ftp
.HostName = "ftp.MySite.com"
.UserName = “MyName”
.Password = “MyPassword”
End With

mySession.Open mySessionOptions

Dim directoryInfo As RemoteDirectoryInfo
Set directoryInfo = mySession.ListDirectory("/MyDir/")

'Get Latest File

Dim myTransferOptions As New TransferOptions
myTransferOptions.TransferMode = TransferMode_Binary

Dim transferResult As TransferOperationResult
Set transferResult = mySession.GetFiles(“/MyDir/MyFile.csv", “C:\Temp\”, False, myTransferOptions)

transferResult.Check

Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
MsgBox "Download of " & transfer.FileName & " succeeded"
Next

mySession.Dispose
---------------

Unfortunately the script example provided for obtaining the latest file is written in C#
// Get list of files in the directory
RemoteDirectoryInfo directoryInfo = session.ListDirectory(remotePath);

// Select the most recent file
RemoteFileInfo latest =
directoryInfo.Files
Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();

I understand how to set the directoryinfo parameter, but does anyone have a VBA example of the query/properties/methods used to identify the most recent file?

Thank you.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
In VBA, you have to iterate the directoryInfo.Files using For Each loop to find the latest one.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License