Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
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)

Options

Topic review

martin

Re: Failed to store new host key

The SshHostKeyPolicy.AcceptNew uses Windows registry to store the host key. It's quite likely that the registry is not writable in the limited Azure function environment. It makes sense as the environment is not persistent. Even if it was writtable, the host key won't be persisted between runs. So it would be as good/bad as using SshHostKeyPolicy.GiveUpSecurityAndAcceptAny.

See also https://winscp.net/eng/docs/faq_hostkey#automation
divya.yandra

Failed to store new host key

Hi,

We are using WinSCP nuget (version: 5.19.3) in our project.
WinSCP nuget is used to connect to a SFTP server from Microsoft Azure function.
Our Microsoft Azure function is a timer trigger function. We are using C# .NET in the timer trigger function.
Our Azure function is working fine in local, but when we have hosted to Azure cloud it is giving below exception when trying to connect to the SFTP server.
Exception:

Messsage: Failed to store new host key. Authentication failed.
Exception type: WinSCP.SessionRemoteException
Failed Method: WinSCP.SessionLogReader.Read

Our Code:
SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "xxx",
    UserName = "xx",
    Password = "xxx",
    PortNumber = "xx",
    SshHostKeyPolicy = SshHostKeyPolicy.AcceptNew
};
 
using (session = new Session())
{                   
    session.Open(sessionOptions);
   
    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary;
    transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;
 
    var localTempPath = $"{Directory.GetCurrentDirectory()}\\{ sftpServer.SFTP.FileName}";
 
    // Download the file
    TransferOperationResult transferOperationResult = session.GetFiles($"{ sftpServer.SFTP.Directory}{ sftpServer.SFTP.FileName}", localTempPath, false, transferOptions);
   
 
    // Read the file
    result = File.ReadAllLines(localTempPath).Select(v => ImportSampleModel.FromCsv(v)).ToList();
 
    // Delete the file
    File.Delete(localTempPath);
}