Connecting to WebDAV doesn't work

Advertisement

Arne Drews
Joined:
Posts:
5
Location:
Germany

Connecting to WebDAV doesn't work

Hi,

I have following data (some text changed for here!) which allows me to connect to a WebDAV via WinSCP client, but doesn't work with the assembly:

HostName: webdav.example.com/storage/me
UserName: MyWebDav
Password: foobar

If I use these data with the Windows client WinSCP, the connect works without any problems!

Now, I tried several things to use these within the assembly, but I get error responses all the time. Here are some examples of my tries:

WinSCP.SessionOptions SessOpts = new WinSCP.SessionOptions
{
    Protocol = WinSCP.Protocol.Webdav
    , PortNumber = 443
    , RootPath = "/"
    , HostName = "webdav.example.com/storage/me"
    , UserName = "MyWebDav"
    , Password = "foobar"
};
 
WinSCP.TransferOptions TransOpts = new WinSCP.TransferOptions();
TransOpts.TransferMode = WinSCP.TransferMode.Binary;
 
using (WinSCP.Session sess = new WinSCP.Session())
{
    sess.Open(SessOpts);
    WinSCP.TransferOperationResult TransferResult = sess.GetFiles("/export/export_*.csv", @"\\srv-11\data\export\", false, TransOpts);
    TransferResult.Check();
}
Result:
WinSCP.SessionRemoteException: Error listing directory '/export'.
WinSCP.SessionOptions SessOpts = new WinSCP.SessionOptions
{
    Protocol = WinSCP.Protocol.Webdav
    , PortNumber = 443
    , WebdavSecure = true
    , RootPath = "/export"
    , HostName = "webdav.example.com/storage/me"
    , UserName = "MyWebDav"
    , Password = "foobar"
};
 
WinSCP.TransferOptions TransOpts = new WinSCP.TransferOptions();
TransOpts.TransferMode = WinSCP.TransferMode.Binary;
 
using (WinSCP.Session sess = new WinSCP.Session())
{
    sess.Open(SessOpts);
    WinSCP.TransferOperationResult TransferResult = sess.GetFiles("/export/export_*.csv", @"\\srv-11\data\export\", false, TransOpts);
    TransferResult.Check();
}
same result:
WinSCP.SessionRemoteException: Error listing directory '/export'.
I'm honest, I haven't any idea what's my mistake, but I know I do something wrong.
Has somebody helpful infos for me?

Thanks!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,468
Location:
Prague, Czechia

Re: Connecting to WebDAV doesn't work

Hostname is just the webdav.example.com.
The /storage/me should go to Session.GetFiles (and possibly to the RootPath).
WinSCP.SessionOptions SessOpts = new WinSCP.SessionOptions
{
    // ...
    // needed only if the root is not WebDAV accessible
    , RootPath = "/storage/me"
    , HostName = "webdav.example.com"
};
sess.GetFiles("/storage/me/export/export_*.csv", @"\\srv-11\data\export\", false, TransOpts);

Reply with quote

Advertisement

You can post new topics in this forum