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

Guest

Re: Connection failed when trying to open a session

Indeed, the RootPath was missing, it's working now.
Thank you!
As for the WebdavSecure = true, it seems that it did fix it.
martin

Re: Connection failed when trying to open a session

If your WebDAV server is implemented in some sub-path only, you might need to set SessionOptions.RootPath:
https://winscp.net/eng/docs/library_sessionoptions#rootpath
WinSCP cannot be aware of such restriction, so I cannot know that the setting is needed, when generating the code.

Btw, was it the WebdavSecure = true that has fixed it?
rl

Re: Connection failed when trying to open a session

Hi, Thank you for your reply.
I generated the code, and now I get "404 Not Found" error for Session.Open.
I checked the "Logging" in the GUI, but couldn't find log files.

My code:
SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Webdav,
    HostName = "x",
    UserName = "xx",
    Password = "xxx",
    WebdavSecure = true,
    TlsHostCertificateFingerprint = "7e:5c:.....",
};
 
using (WinSCP.Session session = new WinSCP.Session())
{
    // Connect
    session.Open(sessionOptions);
}

Thanks
martin

Re: Connection failed when trying to open a session

If GUI works, did you try having it generate a code template for you?
https://winscp.net/eng/docs/ui_generateurl#code

If this does not help, please post session log files both from GUI and the code.
rl

Connection failed when trying to open a session

Hello,
When I try to open a session, I get one of these exceptions (depending on the SessionOptions):
Could not read status line: An existing connection was forcibly closed by the remote host.

or
Could not read status line: connection was closed by server

– I tried running a batch file with an open command – runs successfully.
– WinSCP.exe also connected successfully.
Any suggestion what could be the problem?
Thank you
My code:
var sessionOptions = new SessionOptions
{
    Protocol = Protocol.Webdav,
    HostName = "***.net",
    UserName = "***",
    Password = "***",
    PortNumber = 443,
    WebdavSecure = false,
};
using (var session = new Session())
{
    session.Open(sessionOptions);
    ...
}