Differences
This shows you the differences between the selected revisions of the page.
| script_download_most_recent_file 2020-12-25 | script_download_most_recent_file 2022-06-16 (current) | ||
| Line 8: | Line 8: | ||
| <code powershell> | <code powershell> | ||
| param ( | param ( | ||
| - | $localPath = "c:\downloaded\", | + | $localPath = "c:\downloaded", | 
| - | $remotePath = "/home/user/" | + | $remotePath = "/home/user" | 
| ) | ) | ||
| Line 23: | Line 23: | ||
| UserName = "user" | UserName = "user" | ||
| Password = "mypassword" | Password = "mypassword" | ||
| - | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...=" | + | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." | 
| } | } | ||
| Line 51: | Line 51: | ||
| # Download the selected file | # Download the selected file | ||
| - | $session.GetFiles( | + | $session.GetFileToDirectory($latest.FullName, $localPath) | Out-Null | 
| - | [WinSCP.RemotePath]::EscapeFileMask($latest.FullName), $localPath).Check() | + | |
| } | } | ||
| finally | finally | ||
| Line 89: | Line 88: | ||
| UserName = "user", | UserName = "user", | ||
| Password = "mypassword", | Password = "mypassword", | ||
| - | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...=", | + | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...", | 
| }; | }; | ||
| Line 97: | Line 96: | ||
| session.Open(sessionOptions); | session.Open(sessionOptions); | ||
| - | const string remotePath = "/home/user/"; | + | const string remotePath = "/home/user"; | 
| - | const string localPath = @"C:\downloaded\"; | + | const string localPath = @"C:\downloaded"; | 
| // Get list of files in the directory | // Get list of files in the directory | ||
| Line 117: | Line 116: | ||
| // Download the selected file | // Download the selected file | ||
| - | session.GetFiles( | + | session.GetFileToDirectory(latest.FullName, localPath); | 
| - | RemotePath.EscapeFileMask(latest.FullName), localPath).Check(); | + | |
| } | } | ||
| Line 130: | Line 128: | ||
| } | } | ||
| } | } | ||
| + | </code> | ||
| + | |||
| + | ==== [[vbnet]] VB.NET ==== | ||
| + | |||
| + | The following snippet selects the most recent file from a directory listing. Most of the remaining code should be trivial to translate from the above C# example. | ||
| + | |||
| + | <code vbnet> | ||
| + | Dim latest As RemoteFileInfo = | ||
| + | directoryInfo.Files _ | ||
| + | .Where(Function(file) Not file.IsDirectory) _ | ||
| + | .OrderByDescending(Function(file) file.LastWriteTime) _ | ||
| + | .FirstOrDefault() | ||
| </code> | </code> | ||