Differences
This shows you the differences between the selected revisions of the page.
| library_session_listdirectory 2016-02-03 | library_session_listdirectory 2026-01-16 (current) | ||
| Line 8: | Line 8: | ||
| <code vbnet *> | <code vbnet *> | ||
| - | Public Function ListDirectory(ByVal path As String) As RemoteDirectoryInfo | + | Public Function ListDirectory(path As String) As RemoteDirectoryInfo |
| </code> | </code> | ||
| Line 33: | Line 33: | ||
| ===== [[example]] Examples ===== | ===== [[example]] Examples ===== | ||
| + | |||
| ==== [[csharp]] C# Example ==== | ==== [[csharp]] C# Example ==== | ||
| <code csharp> | <code csharp> | ||
| Line 51: | Line 52: | ||
| UserName = "user", | UserName = "user", | ||
| Password = "mypassword", | Password = "mypassword", | ||
| - | SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." |
| }; | }; | ||
| Line 59: | Line 60: | ||
| session.Open(sessionOptions); | session.Open(sessionOptions); | ||
| - | RemoteDirectoryInfo directory = session.ListDirectory("/home/martin/public_html"); | + | RemoteDirectoryInfo directory = |
| + | ···················session.ListDirectory("/home/martin/public_html"); | ||
| foreach (RemoteFileInfo fileInfo in directory.Files) | foreach (RemoteFileInfo fileInfo in directory.Files) | ||
| { | { | ||
| - | Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}", | + | Console.WriteLine( |
| - | fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, fileInfo.LastWriteTime); | + | ························"{0} with size {1}, permissions {2} and last modification at {3}", |
| + | fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, | ||
| + | ·······················fileInfo.LastWriteTime); | ||
| } | } | ||
| } | } | ||
| Line 95: | Line 99: | ||
| .UserName = "user" | .UserName = "user" | ||
| .Password = "mypassword" | .Password = "mypassword" | ||
| - | .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." |
| End With | End With | ||
| Line 102: | Line 106: | ||
| session.Open(sessionOptions) | session.Open(sessionOptions) | ||
| - | Dim directory As RemoteDirectoryInfo = session.ListDirectory("/home/martin/public_html") | + | Dim directory As RemoteDirectoryInfo = |
| + | ···················session.ListDirectory("/home/martin/public_html") | ||
| Dim fileInfo As RemoteFileInfo | Dim fileInfo As RemoteFileInfo | ||
| For Each fileInfo In directory.Files | For Each fileInfo In directory.Files | ||
| - | Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}", _ | + | Console.WriteLine( |
| - | fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, fileInfo.LastWriteTime) | + | ························"{0} with size {1}, permissions {2} and last modification at {3}", |
| + | fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, | ||
| + | ·······················fileInfo.LastWriteTime) | ||
| Next | Next | ||
| End Using | End Using | ||
| Line 132: | Line 139: | ||
| # Setup session options | # Setup session options | ||
| - | $sessionOptions = New-Object WinSCP.SessionOptions | + | $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ |
| - | ···$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp | + | ········Protocol = [WinSCP.Protocol]::Sftp |
| - | $sessionOptions.HostName = "example.com" | + | ·······HostName = "example.com" |
| - | $sessionOptions.UserName = "user" | + | ·······UserName = "user" |
| - | $sessionOptions.Password = "mypassword" | + | ·······Password = "mypassword" |
| - | $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | ·······SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." |
| + | } | ||
| $session = New-Object WinSCP.Session | $session = New-Object WinSCP.Session | ||
| Line 150: | Line 158: | ||
| foreach ($fileInfo in $directory.Files) | foreach ($fileInfo in $directory.Files) | ||
| { | { | ||
| - | Write-Host ("{0} with size {1}, permissions {2} and last modification at {3}" -f | + | Write-Host ("$($fileInfo.Name) with size $($fileInfo.Length), " + |
| - | $fileInfo.Name, $fileInfo.Length, $fileInfo.FilePermissions, $fileInfo.LastWriteTime) | + | "permissions $($fileInfo.FilePermissions) and " + |
| + | ················"last modification at $($fileInfo.LastWriteTime)") | ||
| } | } | ||
| } | } | ||
| Line 162: | Line 171: | ||
| exit 0 | exit 0 | ||
| } | } | ||
| - | catch [Exception] | + | catch |
| { | { | ||
| - | Write-Host $_.Exception.Message | + | Write-Host "Error: $($_.Exception.Message)" |
| exit 1 | exit 1 | ||
| } | } | ||
| Line 175: | Line 184: | ||
| <code javascript> | <code javascript> | ||
| <job> | <job> | ||
| - | <reference object="WinSCP.Session"/> | + | <reference object="WinSCP.Session"·/> |
| <script language="JScript"> | <script language="JScript"> | ||
| Line 186: | Line 195: | ||
| sessionOptions.UserName = "user"; | sessionOptions.UserName = "user"; | ||
| sessionOptions.Password = "mypassword"; | sessionOptions.Password = "mypassword"; | ||
| - | sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"; | + | sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."; |
| var session = WScript.CreateObject("WinSCP.Session"); | var session = WScript.CreateObject("WinSCP.Session"); | ||
| Line 197: | Line 206: | ||
| var directoryInfo = session.ListDirectory("/home/martin/public_html") | var directoryInfo = session.ListDirectory("/home/martin/public_html") | ||
| - | for (var enumerator = new Enumerator(directoryInfo.Files); !enumerator.atEnd(); enumerator.moveNext()) | + | var enumerator = new Enumerator(directoryInfo.Files); |
| + | for (; !enumerator.atEnd(); enumerator.moveNext()) | ||
| { | { | ||
| var fileInfo = enumerator.item(); | var fileInfo = enumerator.item(); | ||
| Line 228: | Line 238: | ||
| <code vb> | <code vb> | ||
| <job> | <job> | ||
| - | <reference object="WinSCP.Session"/> | + | <reference object="WinSCP.Session"·/> |
| <script language="VBScript"> | <script language="VBScript"> | ||
| Line 241: | Line 251: | ||
| .UserName = "user" | .UserName = "user" | ||
| .Password = "mypassword" | .Password = "mypassword" | ||
| - | .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." |
| End With | End With | ||
| Line 269: | Line 279: | ||
| ==== Real-Life Examples ==== | ==== Real-Life Examples ==== | ||
| - | * [[script_download_most_recent_file|Downloading the most recent file]]; | + | * [[script_download_most_recent_file|*]]; |
| - | ··* [[library_example_listing_files_matching_wildcard|Listing files matching wildcard]]; | + | * [[script_custom_listing_format_csv|*]]. |
| - | * [[library_example_recursive_search_text|Search recursively for text in remote directory / Grep files over SFTP/FTP protocol]]; | + | |
| - | ··* [[library_example_recursive_download_custom_error_handling|Recursively download directory tree with custom error handling]]; | + | |
| - | * [[library_example_find_duplicate_files|Find duplicate files in SFTP/FTP server]]; | + | |
| - | * [[script_custom_listing_format_csv|Custom directory listing format (CSV)]]. | + | |