Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


1. Where is Session.DebugLogPath ?
2. The dll is in that path because this is running on a work computer and that is where it is installed to.

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

I am running in line by line to test if it works in powershell ISE.

Re: SFTP file from server

How are you executing your PowerShell script?

SFTP file from server

    # 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
        # Connect
        # 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
        # Print results
        foreach ($transfer in $transferResult.Transfers)
            Write-Host "Download of $($transfer.FileName) succeeded"
        # Disconnect, clean up
    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?