Cannot reset SFTP login password with SessionOptions() using NewPassword or SecurePassword

Advertisement

james07030
Joined:
Posts:
1
Location:
United States

Cannot reset SFTP login password with SessionOptions() using NewPassword or SecurePassword

Hi everyone, I need help to reset SFTP server login password using C# WinSCP API automatically in the password expiration period. but either of the following method would not work:
1. Using NewPassword {} in SessionOptions API
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = hostName,
UserName = loginName,
Password = passwordOld,
NewPassword = passwordNew,
SshHostKeyFingerprint = fingerPrint,
};
using (Session session = new Session())
{
session.Open(sessionOptions);
2. Using SecureNewPassword {} in SessionOptions API

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = hostName,
UserName = loginName,
SecurePassword = SecPasswordOld,
SecureNewPassword = SecPasswordNew,
SshHostKeyFingerprint = fingerPrint,
};
using (Session session = new Session())
{
session.Open(sessionOptions);

3. Using passwordOld + "/" + passwordNew + "/" + passwordNew for login

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
//Protocol = Protocol.Ftp,
HostName = hostName,
UserName = loginName,
Password = passwordOld + "/" + passwordNew + "/" + passwordNew,
SshHostKeyFingerprint = fingerPrint,
};
using (Session session = new Session())
{
session.Open(sessionOptions);
4. Using unix shell scrip "passwd" command

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = hostName,
UserName = loginName,
Password = passwordOld,
SshHostKeyFingerprint = fingerPrint,
};
using (Session session = new Session())
{
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
string passwordChange = passwordOld + "/" + passwordNew + "/" + passwordNew;
string comChangePass = string.Format("echo -n " + passwordChange + " | passwd");
CommandExecutionResult result = session.ExecuteCommand(comChangePass);
MessageBox.Show("Password change command : " + comChangePass);

result.Check();
string output = result.Output;

MessageBox.Show("Password changed result: " + output);
Anybody knows how to use WinScp API to change password by program?
Thank you very much!
James

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

Re: Cannot reset SFTP login password with SessionOptions() using NewPassword or SecurePassword

Sorry, but "would not work" is pretty vague. Can you post some log files?

Reply with quote

Guest

Re: Cannot reset SFTP login password with SessionOptions() using NewPassword or SecurePassword

martin wrote:

Sorry, but "would not work" is pretty vague. Can you post some log files?
Thank you so much, here is the log I have:
My Code:

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
//Protocol = Protocol.Ftp,
HostName = hostName,
UserName = loginName,
Password = passwordOld,
NewPassword = passwordNew,
SshHostKeyFingerprint = fingerPrint,
};
using (Session session = new Session())
{
session.Open(sessionOptions);
My Error Log:

INFO 14 Sep 2018 10:52:48,367 FDCCPasswordReset.Program - Error! SFTP connection failed.WinSCP.SessionRemoteException: Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "MyUserName1".
Access denied.

Authentication failed.
at WinSCP.SessionLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.Session.WaitForGroup()
at WinSCP.Session.Open(SessionOptions sessionOptions)
at FICCPasswordReset.Program.Main(String[] args)

Reply with quote

Advertisement

You can post new topics in this forum