PowerShell code in documentation is not working

Advertisement

Advertisement

francesco84mantovani@gmail.com
Joined:
Posts:
14
Location:
Lausanne

Basic code and logs

Hello,

I have a version of the code I'm using:
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "1*.***.***.*0"
    UserName = "a*****1"
    Password = "m*********9"
    SshHostKeyFingerprint = "ssh-ed25519 255 eeDKU******************************UNg="
}
 
$session = New-Object WinSCP.Session
$session.SessionLogPath = "C:\Users\FMV\Documents\logging.log" 
 
try
{
    # Connect
    $session.Open($sessionOptions)
    # Your code
   
    # From VM to Laptop
    $session.GetFiles("full***********.csv", "C:\Users\fmv\Downloads\" )
}
finally
{
    $session.Dispose()
}

And in attach the logs.
I was able to test this code on a VM that I created especially for this issue. Everything works.

VM TEST:
– WinSCP Version 5.19.2
– rsa2
– Command: working
– Powershell Script: working

PROD:
– WinSCP Version 5.17.10
– ssh-ed25519
– Command: working
– PowerShell Script: fails

Can the hotkey be the problem?
Last edited by francesco84mantovani@gmail.com on 2021-09-22 15:21; edited 1 time in total
Description: Logs on test VM environment
Description: Logs on PROD (masqued)

Reply with quote

francesco84mantovani@gmail.com
Joined:
Posts:
14
Location:
Lausanne

WinSCP portable version

I have download the portable version of WinSCP and I pointed the Add-Type -Path to the \netstandard2.0\WinSCPnet.dll and \net40\WinSCPnet.dll. Still failing for both :(

The error in PowerShell is always the same:
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "a***1".
Access denied.
Authentication failed."
At C:\Users\FMV\Documents\test.ps1:18 char:5
+     $session.Open($sessionOptions)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SessionRemoteException
But the exact same code works on my Test VM environment.
Where can be the problem?

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: PowerShell code in documentation is not working

But those logs shows connections to different servers. Or what is your VM? I've understood that it is a machine, from where you can connect. Or did you use the VM as a test server? Can you connect to your production server anyhow? In WinSCP GUI? From any other local machine?

Reply with quote

francesco84mantovani@gmail.com
Joined:
Posts:
14
Location:
Lausanne

VM vs production

Yes, I'm connecting to two different servers. That's why you have successful login to VM and fails to the production server.
Yes, I can successfully connect to the production using WinSCP GUI but using the PowerShell code of your guides it fails.
Do you think it can be related to the
SshHostKeyFingerprint
being different?
Is there a way I can change the
SshHostKeyFingerprint
from
ssh-ed25519
to
rsa2
and test?

Because that is the only difference between the VM and the production

Reply with quote

martin
Site Admin
martin avatar

Re: VM vs production

It's unlikely that the host key is the culprit. Post logs from GUI for comparison.

Also enable password logging and compare GUI and code logs to double check that you use the same password in both cases.

Reply with quote

Advertisement

You can post new topics in this forum