Post a reply

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

gtrennert

SessionLocalException on simple Session.Open in Azure function (C#)

Hello,
First I generated a simple console application to see if the generated by WinSCP works fine – and this was the case
Now I try to write an Azure function using WinSCP – in the same way – the same parameters – and I get an exception on Session.Open (SessionLocalException)

My code:
public static async Task<IActionResult> WriteFile(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
{
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Sftp,
        HostName = "xxx",
        UserName = "xxx",
        Password = "xxx",
        SshHostKeyFingerprint = "xxx",
    };
    using (Session session = new Session())
    {
        try
        {
            session.Open(sessionOptions);
        }
        catch (SessionLocalException)
        {
            content = JsonConvert.SerializeObject(new { success = false, exception = "SessionLocalException", condition = "Error communicating with winscp.com. See the exception documentation for details." });
            return (ActionResult)new OkObjectResult($"{content}");
        }

Exception documentation for details does not help very much
Could anybody help me?