public async Task <WebDAVFile> GET(WebDAVLocation location, string filename) { _logger.LogDebug($"Getting file at {location}/{filename}"); var uri = getUrlForFilename(location.Value, filename); return(await GET(uri)); }
public async Task <bool> DELETE(WebDAVLocation location, string filename) { _logger.LogDebug("Deleting file at {Location}/{Filename}", location, filename); var uri = getUrlForFilename(location.Value, filename); var result = await GetClient().DeleteAsync(uri); return(result.IsSuccessStatusCode); }
public async Task <bool> PUT(WebDAVLocation location, string filename, byte[] contents) { _logger.LogDebug("Putting file {Location}/{Filename}", location, filename); var uri = getUrlForFilename(location.Value, filename); var httpContent = new ByteArrayContent(contents); var result = await GetClient().PutAsync(uri, httpContent); return(result.IsSuccessStatusCode); }
public async Task <bool> UNZIP(WebDAVLocation location, string filename) { _logger.LogDebug("Unzipping file at {Location}/{Filename}", location, filename); var uri = getUrlForFilename(location.Value, filename); var request = new HttpRequestMessage(HttpMethod.Post, uri) { Content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("method", "UNZIP") }) }; var result = await GetClient().SendAsync(request); return(result.IsSuccessStatusCode); }
public async Task <bool> PUT(WebDAVLocation location, string filename, Stream contents, TransferProgressReporter.ReportProgressHandler progressHandler = null) { _logger.LogDebug("Putting file {Location}/{Filename}", location, filename); var uri = getUrlForFilename(location.Value, filename); var reporter = new TransferProgressReporter(); if (progressHandler != null) { reporter.Handler += progressHandler; } var httpContent = new ProgressReportingHttpContent(contents, reporter); var result = await GetClient().PutAsync(uri, httpContent).ConfigureAwait(false); return(result.IsSuccessStatusCode); }
public async Task <bool> MakeDirectory(WebDAVLocation location, string directory) { _logger.LogDebug("Creating Directory {Location}/{Directory}", location, directory); var uri = getUrlForFilename(location.Value, directory); var file = await GET(location, directory); if (file != null) { _logger.LogDebug($"Directory {location}/{directory} exists"); return(true); } var request = new HttpRequestMessage { RequestUri = new Uri($"https://{_env.Server}{uri}"), Method = new HttpMethod("MKCOL") }; var result = await GetClient().SendAsync(request); return(result.IsSuccessStatusCode); }
public async Task <IList <WebDAVFile> > ListDirectory(WebDAVLocation location, string directory) { _logger.LogDebug($"Listing Directory {location}/{directory}"); var uri = getUrlForFilename(location.Value, directory); var request = new HttpRequestMessage { RequestUri = new Uri($"https://{_env.Server}{uri}"), Method = new HttpMethod("PROPFIND") }; var result = await GetClient().SendAsync(request); result.EnsureSuccessStatusCode(); var bodyStream = await result.Content.ReadAsStreamAsync(); var collection = await XElement.LoadAsync(bodyStream, LoadOptions.None, CancellationToken.None); var responses = collection.Descendants(DAV + "response"); var files = responses.Select(FileFromXML); return(files.Skip(1).ToList()); }
public async Task <WebDAVFile> GETInfo(WebDAVLocation location, string path) { var filePath = getUrlForFilename(location.Value, path); return(await GETInfo(filePath)); }
public async Task <Stream> GETStream(WebDAVLocation location, string path) { var filePath = getUrlForFilename(location.Value, path); return(await GETStream(filePath)); }