Differences

This shows you the differences between the selected revisions of the page.

script_download_timestamped_filename 2015-12-16 script_download_timestamped_filename 2022-06-16 (current)
Line 1: Line 1:
-====== [[download_timestamped_filename]] Downloading file to timestamped-filename ======+====== Downloading file to timestamped-filename ======
-===== Using WinSCP .NET Assembly =====+===== [[library]] Using WinSCP .NET Assembly =====
Use [[library|WinSCP .NET assembly]] from your favorite language. Use relevant construct of your language or API of your runtime environment for the file name formatting. Use [[library|WinSCP .NET assembly]] from your favorite language. Use relevant construct of your language or API of your runtime environment for the file name formatting.
Line 19: Line 19:
    # 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 34: Line 35:
        # Format timestamp         # Format timestamp
-        $stamp = $(Get-Date -f "yyyyMMddHHmmss")+        $stamp = $(Get-Date -Format "yyyyMMddHHmmss")
        # Download the file and throw on any error         # Download the file and throw on any error
Line 49: Line 50:
    exit 0     exit 0
} }
-catch [Exception]+catch
{ {
-    Write-Host $_.Exception.Message+    Write-Host "Error: $($_.Exception.Message)"
    exit 1     exit 1
} }
Line 60: Line 61:
<code winscp> <code winscp>
-option batch abort 
-option confirm off 
open mysession open mysession
get "/home/user/download.txt" "C:\downloaded\download.txt.%TIMESTAMP#yyyymmddhhnnss%" get "/home/user/download.txt" "C:\downloaded\download.txt.%TIMESTAMP#yyyymmddhhnnss%"

Last modified: by martin