GUI and WinSCP.com work, Powershell does not

Advertisement

maheller08
Joined:
Posts:
4
Location:
PA

GUI and WinSCP.com work, Powershell does not

The important part of the Powershell is this. The password has a $ in it. The session log and debug logs are attached and the logs from the GUI when it worked. Any help is greatly appreciated. Please let me know if more information is needed. WinSCP 5.1.4

Get this error from the script. "Connection has been unexpectedly closed. Server sent command exit status 0."

. 2013-05-14 16:09:06.800 Attempting keyboard-interactive authentication
. 2013-05-14 16:09:07.002 Prompt (6, SSH server: Password Authentication, Using keyboard-interactive authentication., xxxxxx's password:)
. 2013-05-14 16:09:07.002 Using stored password.
. 2013-05-14 16:09:08.999 Keyboard-interactive authentication failed
! 2013-05-14 16:09:08.999 Access denied
. 2013-05-14 16:09:08.999 Attempting keyboard-interactive authentication
. 2013-05-14 16:09:09.233 Prompt (6, SSH server: Password Authentication, Using keyboard-interactive authentication., xxxxxxx's password:)
. 2013-05-14 16:09:09.233 Disconnected: Unable to authenticate


try
{
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("WinSCP.dll") | Out-Null

# Setup session options

$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "xxxxx"
$sessionOptions.UserName = "xxxxx"
$sessionOptions.Password = "xxxxx"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"


$session = New-Object WinSCP.Session
$session.SessionLogPath = "seslog.txt"
$session.DebugLogPath = "deblog.txt"

try
{
# Connect
$session.Open($sessionOptions)

# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Automatic

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: GUI and WinSCP.com work, Powershell does not

I can see one difference. In GUI, you have "keyboard interactive" authentication disabled. As a consequence GUI is using password authentication, while .NET library is using keyboard interactive authentication.

Is it by purpose? I actually do not see, how this could cause your problem, but it's definitely worth trying.

See https://winscp.net/eng/docs/rawsettings

Reply with quote

maheller08
Joined:
Posts:
4
Location:
PA

Re: GUI and WinSCP.com work, Powershell does not

martin wrote:

I can see one difference. In GUI, you have "keyboard interactive" authentication disabled. As a consequence GUI is using password authentication, while .NET library is using keyboard interactive authentication.

Is it by purpose? I actually do not see, how this could cause your problem, but it's definitely worth trying.

See https://winscp.net/eng/docs/rawsettings

With the GUI I actually tried it with and without attempt keyboard interactive authentication enabled at it works both ways with the GUI. It appears that the remote server, which is not under my control, is not accepting the password from the Powershell script. I looked for, but could not find a way to disable keyboard interactive authentication with the .Net library. Is there a way to do that?

Thank you for your help.
Mark

Reply with quote

maheller08
Joined:
Posts:
4
Location:
PA

Re: GUI and WinSCP.com work, Powershell does not

maheller08 wrote:

martin wrote:

I can see one difference. In GUI, you have "keyboard interactive" authentication disabled. As a consequence GUI is using password authentication, while .NET library is using keyboard interactive authentication.

Is it by purpose? I actually do not see, how this could cause your problem, but it's definitely worth trying.

See https://winscp.net/eng/docs/rawsettings

With the GUI I actually tried it with and without attempt keyboard interactive authentication enabled at it works both ways with the GUI. It appears that the remote server, which is not under my control, is not accepting the password from the Powershell script. I looked for, but could not find a way to disable keyboard interactive authentication with the .Net library. Is there a way to do that?

Thank you for your help.
Mark

No matter what raw settings I try for authentication the Powershell script will not authenticate. I resorted to creating a VB application. For what ever reason that works fine. It is a mystery to me.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: GUI and WinSCP.com work, Powershell does not

Ok, I took a look on PowerShell string syntax, to find that dollar sign has special meaning, when inside souble-quotes, so you have to escape it. Are you aware of this?

Possibilities:
- use tick sign to escape it: "aaa`$bbb"
- using single quotes: 'aaa$bbb'

Reply with quote

Advertisement

maheller08
Joined:
Posts:
4
Location:
PA

Re: GUI and WinSCP.com work, Powershell does not

martin wrote:

Ok, I took a look on PowerShell string syntax, to find that dollar sign has special meaning, when inside souble-quotes, so you have to escape it. Are you aware of this?

Possibilities:
- use tick sign to escape it: "aaa`$bbb"
- using single quotes: 'aaa$bbb'

I should have recogonized that fact, but it did not sink in. Thank you for the insight. The script now works great.

Thank you very much.

Reply with quote

Advertisement

You can post new topics in this forum