public override WebResponse GetResponse() { WebResponse response = null; if (this.client == null || !this.client.IsConnected) { this.client = SshRequestCreator.GetOrCreateClient(this); } switch (this.Method) { case IOConnection.WrmDeleteFile: response = SshWebResponse.GetDeleteResponse(this.client, this.RequestUri.AbsolutePath); break; case IOConnection.WrmMoveFile: var moveTo = this.Headers[IOConnection.WrhMoveFileTo]; var authority = this.RequestUri.GetLeftPart(UriPartial.Authority); if (moveTo?.StartsWith(authority) == true) { response = SshWebResponse.GetMoveResponse(this.client, this.RequestUri.AbsolutePath.TrimStart('/'), moveTo.Substring(authority.Length).TrimStart('/')); } break; case null: response = SshWebResponse.GetDownloadResponse(this.client, this.RequestUri.AbsolutePath); break; } return(response ?? new SshWebResponse()); }
public static SshWebResponse GetMoveResponse(SftpClient client, string pathFrom, string pathTo) { var response = new SshWebResponse(); if (client.Exists(pathFrom)) { client.RenameFile(pathFrom, pathTo); } return(response); }
public static SshWebResponse GetDeleteResponse(SftpClient client, string path) { var response = new SshWebResponse(); if (client.Exists(path)) { client.DeleteFile(path); } path = path.TrimStart('/'); if (client.Exists(path)) { client.DeleteFile(path); } return(response); }
public static SshWebResponse GetDownloadResponse(SftpClient client, string path) { var response = new SshWebResponse(); if (client.Exists(path)) { response.stream = client.OpenRead(path); return(response); } path = path.TrimStart('/'); if (client.Exists(path)) { response.stream = client.OpenRead(path); return(response); } return(response); }