private IEnumerable <WebRoute> ListFolder(S3WebRequest s3WebRequest) { s3WebRequest.Method = S3RequestMethods.ListObject; using (S3ObjectWebResponse <ListObjectsResponse> resp = (S3ObjectWebResponse <ListObjectsResponse>)s3WebRequest.GetResponse()) { return(resp.GetObject().S3Objects.Select(o => { S3WebRequest s3Req = s3WebRequest.Clone(o.Key);; return new WebRoute(s3Req, Convert.ToUInt64(o.Size)); })); } }
internal async Task Remove() { if (request is HttpWebRequest) { throw new NotSupportedException("Cannot remove HTTP object"); } if (request is FileWebRequest) { FileInfo file = new FileInfo(request.RequestUri.LocalPath); file.Delete(); return; } if (request is FtpWebRequest) { var ftpWebRequest = (FtpWebRequest)request.CloneRequest(request.RequestUri); ftpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile; using (FtpWebResponse resp = (FtpWebResponse)ftpWebRequest.GetResponse()) { if (!(resp.StatusCode != FtpStatusCode.CommandOK)) { throw new Exception(string.Format("FTP server returned an error ({0})", resp.StatusCode)); } } return; } if (request is S3WebRequest) { var s3WebRequest = (S3WebRequest)request.CloneRequest(request.RequestUri); s3WebRequest.Method = S3RequestMethods.DeleteObject; using (S3ObjectWebResponse <DeleteObjectResponse> resp = (S3ObjectWebResponse <DeleteObjectResponse>)s3WebRequest.GetResponse()) { if (!(resp.GetObject().HttpStatusCode == HttpStatusCode.OK)) { throw new Exception(string.Format("S3 server returned an error ({0})", resp.GetObject().HttpStatusCode)); } } return; } throw new NotSupportedException(string.Format("Cannot remove {0} object", request.GetType())); }