SFTP file from server

Advertisement

talormanda
Joined:
Posts:
3
Location:
USA

SFTP file from server

try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "C:\ProgramData\Microsoft\AppV\Client\Integration\76D73676-A43A-4890-9049-8283D31CD7E0\Root\VFS\ProgramFilesX86\WinSCP\WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "servername"
        UserName = "mgr"
        Password = "password"
        SshHostKeyFingerprint = "ssh-ed25519 256 #stuff_here#"
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Download files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
 
        $transferResult =
            $session.GetFiles("/sunquest/printfiles/testfile.txt", "C:\test", $False, $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host "Download of $($transfer.FileName) succeeded"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

I am getting the following error after running the above:
Error: Cannot initialize external console.
Request event
System Error. Code: 2.
The system cannot find the file specified

If I connect to the server via WinSCP normally, I can access the path and touch the file. I am unsure what is wrong. Could it be that my starting directory for the account is in /sunquest/mgr , and I have to change directories somehow?

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Can you post debug log file (Session.DebugLogPath) for that?
Why do you have the DLL in that path? (C:\ProgramData\Microsoft\AppV\...)

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum