SFTP Authentication error

Advertisement

stefanom
Joined:
Posts:
2
Location:
ITALY

SFTP Authentication error

Hi,
I have a problem with SFTP authentication in C# code.
When I invoke the Open() method of the session, I get this error:
**Connessione chiusa in modo imprevisto.** Il server ha inviato un comando stato uscita 0.
I can connect with GUI, and this is the code used to open session programmatically (WinSCP suggestion):
// Imposta le opzioni di sessione
SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "89.96.90.70",
    UserName = "DML_ftp",
    Password = ...,
    SshHostKeyFingerprint = "ssh-ed25519 255 -----------------------------------",
};
using (Session session = new Session())
{
    // Connetti
    session.Open(sessionOptions);
 
    // Il tuo codice
}
The password doesn't contains special chars.
I can't understand why I get this error. Can anyone help me?

This is the log:
. 2021-09-23 08:23:25.578 --------------------------------------------------------------------------
. 2021-09-23 08:23:25.578 WinSCP Versione 5.19.2 (Build 11614) (OS 10.0.19043 - Windows 10 Enterprise)
. 2021-09-23 08:23:25.578 Configuration: nul
. 2021-09-23 08:23:25.578 Log level: Normal
. 2021-09-23 08:23:25.578 Local account: DESKTOP-K1G5M6U\stefa
. 2021-09-23 08:23:25.578 Working directory: C:\Program Files (x86)\WinSCP
. 2021-09-23 08:23:25.578 Process ID: 3048
. 2021-09-23 08:23:25.594 Ancestor processes: SPB.CommunicationServer, devenv, explorer, ...
. 2021-09-23 08:23:25.594 Command-line: "C:\Program Files (x86)\WinSCP\winscp.exe" /xmllog="C:\Users\stefa\AppData\Local\Temp\wscp48AC.0028C5F3.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /stdout /stdin /dotnet=5.19.2  /ini=nul /log="c:\temp\logs\winscp.txt"  /console /consoleinstance=_18604_24049039_368
. 2021-09-23 08:23:25.595 Time zone: Current: GMT+2, Standard: GMT+1 (ora solare Europa occidentale), DST: GMT+2 (ora legale Europa occidentale), DST Start: 28/03/2021, DST End: 31/10/2021
. 2021-09-23 08:23:25.595 Login time: giovedì 23 settembre 2021 08:23:25
. 2021-09-23 08:23:25.595 --------------------------------------------------------------------------
. 2021-09-23 08:23:25.595 Script: Retrospectively logging previous script records:
> 2021-09-23 08:23:25.595 Script: option batch on
< 2021-09-23 08:23:25.595 Script: batch           on        
< 2021-09-23 08:23:25.595 Script: reconnecttime   120       
> 2021-09-23 08:23:25.595 Script: option confirm off
< 2021-09-23 08:23:25.595 Script: confirm         off       
> 2021-09-23 08:23:25.595 Script: option reconnecttime 120
< 2021-09-23 08:23:25.595 Script: reconnecttime   120       
> 2021-09-23 08:23:25.595 Script: open sftp://DML_ftp:***@storage.spbitalia.it:22 -hostkey="ssh-ed25519-llCHZM4dCBDUAN9cLVJ79Xq1Sx6CkmLKU6pjYTwBp4k=" -timeout=15 -newpassword=***
. 2021-09-23 08:23:25.595 --------------------------------------------------------------------------
. 2021-09-23 08:23:25.595 Session name: DML_ftp@storage.spbitalia.it (Ad-Hoc site)
. 2021-09-23 08:23:25.595 Host name: storage.spbitalia.it (Port: 22)
. 2021-09-23 08:23:25.595 User name: DML_ftp (Password: Yes, Key file: No, Passphrase: No)
. 2021-09-23 08:23:25.595 Tunnel: No
. 2021-09-23 08:23:25.595 Transfer Protocol: SFTP
. 2021-09-23 08:23:25.595 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2021-09-23 08:23:25.595 Disable Nagle: No
. 2021-09-23 08:23:25.595 Proxy: None
. 2021-09-23 08:23:25.595 Send buffer: 262144
. 2021-09-23 08:23:25.595 SSH protocol version: 2; Compression: No
. 2021-09-23 08:23:25.595 Bypass authentication: No
. 2021-09-23 08:23:25.595 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2021-09-23 08:23:25.595 GSSAPI: KEX: No; Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2021-09-23 08:23:25.595 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2021-09-23 08:23:25.595 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2021-09-23 08:23:25.595 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2021-09-23 08:23:25.595 Simple channel: Yes
. 2021-09-23 08:23:25.595 Return code variable: Autodetect; Lookup user groups: Auto
. 2021-09-23 08:23:25.595 Shell: default
. 2021-09-23 08:23:25.595 EOL: LF, UTF: Auto
. 2021-09-23 08:23:25.595 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2021-09-23 08:23:25.595 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2021-09-23 08:23:25.595 SFTP Bugs: Auto,Auto
. 2021-09-23 08:23:25.595 SFTP Server: default
. 2021-09-23 08:23:25.595 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2021-09-23 08:23:25.595 Cache directory changes: Yes, Permanent: Yes
. 2021-09-23 08:23:25.595 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2021-09-23 08:23:25.595 DST mode: Unix
. 2021-09-23 08:23:25.595 --------------------------------------------------------------------------
< 2021-09-23 08:23:25.595 Script: Ricerca host ...
. 2021-09-23 08:23:25.596 Looking up host "storage.spbitalia.it" for SSH connection
. 2021-09-23 08:23:25.600 Connecting to 89.96.90.70 port 22
< 2021-09-23 08:23:25.642 Script: Connessione host ...
. 2021-09-23 08:23:25.642 We claim version: SSH-2.0-WinSCP_release_5.19.2
. 2021-09-23 08:23:25.743 Remote version: SSH-2.0-OpenSSH_6.8p1-hpn14v6
. 2021-09-23 08:23:25.743 Using SSH protocol version 2
. 2021-09-23 08:23:25.747 Have a known host key of type ssh-ed25519
. 2021-09-23 08:23:25.785 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2021-09-23 08:23:25.917 Server also has ecdsa-sha2-nistp256/ssh-rsa/ssh-dss host keys, but we don't know any of them
. 2021-09-23 08:23:25.917 Host key fingerprint is:
. 2021-09-23 08:23:25.917 ssh-ed25519 255 b3:0c:e4:61:ba:c1:2c:77:51:09:99:d2:90:1a:0c:8d llCHZM4dCBDUAN9cLVJ79Xq1Sx6CkmLKU6pjYTwBp4k=
. 2021-09-23 08:23:25.918 Host key matches configured key fingerprint
. 2021-09-23 08:23:25.918 Initialised AES-256 SDCTR (AES-NI accelerated) [aes256-ctr] outbound encryption
. 2021-09-23 08:23:25.918 Initialised HMAC-SHA-256 outbound MAC algorithm
. 2021-09-23 08:23:25.918 Initialised AES-256 SDCTR (AES-NI accelerated) [aes256-ctr] inbound encryption
. 2021-09-23 08:23:25.918 Initialised HMAC-SHA-256 inbound MAC algorithm
! 2021-09-23 08:23:25.951 Using username "DML_ftp".
< 2021-09-23 08:23:25.951 Script: Usa nome utente "DML_ftp".
. 2021-09-23 08:23:25.989 Server offered these authentication methods: publickey,password
. 2021-09-23 08:23:25.989 Prompt (new password, "New SSH password", <no instructions>, "Current password (blank for previously entered password): "2 more)
< 2021-09-23 08:23:25.989 Script: Modifica password...
. 2021-09-23 08:23:25.989 Using stored password and new password.
. 2021-09-23 08:23:25.989 Sent new password
. 2021-09-23 08:23:26.024 Password authentication failed
! 2021-09-23 08:23:26.024 Access denied
< 2021-09-23 08:23:26.024 Script: Accesso negato
. 2021-09-23 08:23:26.024 Server offered these authentication methods: publickey,password
. 2021-09-23 08:23:26.024 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2021-09-23 08:23:26.024 User aborted during password authentication
. 2021-09-23 08:23:26.024 Attempt to close connection due to fatal exception:
* 2021-09-23 08:23:26.024 **Connessione chiusa in modo imprevisto.** Il server ha inviato un comando stato uscita 0.
. 2021-09-23 08:23:26.024 Closing connection.
< 2021-09-23 08:23:26.025 Script: Connessione chiusa in modo imprevisto. Il server ha inviato un comando stato uscita 0.
< 2021-09-23 08:23:26.025 Registro di autenticazione (vedi registro di sessione per i dettagli):
< 2021-09-23 08:23:26.025 Usa nome utente "DML_ftp".
< 2021-09-23 08:23:26.025 Accesso negato
< 2021-09-23 08:23:26.025

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,605
Location:
Prague, Czechia

Re: SFTP Authentication error

Enable logging and password logging both in GUI and the code and compare the logs to see if the same password is really in use.
In code you enable logging using Session.SessionLogPath and password logging using Logging\LogSensitive raw configuration settings.
https://winscp.net/eng/docs/library_session#sessionlogpath
https://winscp.net/eng/docs/rawconfig#logging_logsensitive

If this does not help, post both (English) logs here (without the password if you want).

Reply with quote

stefanom

Solved

Issue solved.
Thank you for (precious) help.
My mistake was that I was setting string.Empty value in NewPassword session option (not a good practice).

Reply with quote

Advertisement

You can post new topics in this forum