skazantsev / WebDavClient

Asynchronous cross-platform WebDAV client for .NET Core
MIT License
155 stars 30 forks source link

Error 403 in PutFile and GetRawFile but no in GetProcessedFile #61

Closed elgransan closed 3 years ago

elgransan commented 3 years ago

I'm using https with basic authentication, I can connect and read a file with GetProcessedFile but the methods PutFile and GetRawFile returns allways 403 Forbidden

        // Tls1.2
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        // Ignore certificate check
        ServicePointManager.ServerCertificateValidationCallback +=
        (se, cert, chain, sslerror) =>
        {
            return true;
        };

        WebDavClientParams clientParams = new WebDavClientParams();
        clientParams.BaseAddress = new Uri(config.host); // HTTPS URI
        clientParams.Credentials = new NetworkCredential(config.user, config.pass);
        var client = new WebDavClient(clientParams);

            foreach (string file in Directory.EnumerateFiles(this.localFolder, "*", SearchOption.AllDirectories))
            {
                string dirName = file.Replace(this.localFolder, "");
                dirName = dirName.Replace("\\", "/");
                string dest = config.host + config.remoteFolder + dirName;

                    var response = await client.GetRawFile(config.host + "/test.txt"); ->status code 403
                    var response2 = await client.GetProcessedFile(config.host + "/test.txt"); -> status code 200
                    var response1 = await client.PutFile(dest, File.OpenRead(file)); -> status code 403
         }

I want to upload local files to the server any idea?

elgransan commented 3 years ago

Seems my user name was wrong, I was desoriented with the status 200 on GetProcessedFile

skazantsev commented 3 years ago

Cool, I'm glad it's resolved.