How to connect to a server that does not allow an access to the root path?

With HTTP-based servers (WebDAV or S3), it is possible that the server does not allow an access to the URL root path, like https://www.example.com/.

With WebDAV, the server often runs on a subfolder, like https://www.example.com/dav/. Accessing a folder outside of the WebDAV root will often result in a error message “405 Method Not Allowed”.

With S3, your credentials may disallow an access to a bucket list, which WinSCP otherwise presents as a root.

In these cases, you have to configure WinSCP to start in the subfolder straight away.

GUI

In GUI, you do that by filling the path (e.g. /dav or /bucketname) to Remote directory box on Directories page of Advanced Site Settings dialog. Particularly with WebDAV, a handy shortcut is to paste a full URL (https://www.example.com/dav/) on Login dialog. WinSCP will parse the path out of the URL automatically.

Scripting

In scripting, specify the path directly in session URL in open command:

open davs://www.example.com/dav/

.NET assembly

In .NET assembly, use SessionOptions.RootPath:

C# example:

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Webdav,
    HostName = "www.example.com",
    RootPath = "/dav",
    ...
};

Generated Script/Code

Note that even if you have the script or code generated from a working WinSCP GUI session, it won’t include the root path, as the GUI cannot be aware of the root path restriction.

Last modified: by 208.127.42.58