comparison src/com/trilead/ssh2/SFTPException.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1
2 package com.trilead.ssh2;
3
4 import java.io.IOException;
5
6 import com.trilead.ssh2.sftp.ErrorCodes;
7
8
9 /**
10 * Used in combination with the SFTPv3Client. This exception wraps
11 * error messages sent by the SFTP server.
12 *
13 * @author Christian Plattner, plattner@trilead.com
14 * @version $Id: SFTPException.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
15 */
16
17 public class SFTPException extends IOException {
18 private static final long serialVersionUID = 578654644222421811L;
19
20 private final String sftpErrorMessage;
21 private final int sftpErrorCode;
22
23 private static String constructMessage(String s, int errorCode) {
24 String[] detail = ErrorCodes.getDescription(errorCode);
25
26 if (detail == null)
27 return s + " (UNKNOW SFTP ERROR CODE)";
28
29 return s + " (" + detail[0] + ": " + detail[1] + ")";
30 }
31
32 SFTPException(String msg, int errorCode) {
33 super(constructMessage(msg, errorCode));
34 sftpErrorMessage = msg;
35 sftpErrorCode = errorCode;
36 }
37
38 /**
39 * Get the error message sent by the server. Often, this
40 * message does not help a lot (e.g., "failure").
41 *
42 * @return the plain string as sent by the server.
43 */
44 public String getServerErrorMessage() {
45 return sftpErrorMessage;
46 }
47
48 /**
49 * Get the error code sent by the server.
50 *
51 * @return an error code as defined in the SFTP specs.
52 */
53 public int getServerErrorCode() {
54 return sftpErrorCode;
55 }
56
57 /**
58 * Get the symbolic name of the error code as given in the SFTP specs.
59 *
60 * @return e.g., "SSH_FX_INVALID_FILENAME".
61 */
62 public String getServerErrorCodeSymbol() {
63 String[] detail = ErrorCodes.getDescription(sftpErrorCode);
64
65 if (detail == null)
66 return "UNKNOW SFTP ERROR CODE " + sftpErrorCode;
67
68 return detail[0];
69 }
70
71 /**
72 * Get the description of the error code as given in the SFTP specs.
73 *
74 * @return e.g., "The filename is not valid."
75 */
76 public String getServerErrorCodeVerbose() {
77 String[] detail = ErrorCodes.getDescription(sftpErrorCode);
78
79 if (detail == null)
80 return "The error code " + sftpErrorCode + " is unknown.";
81
82 return detail[1];
83 }
84 }