01: package ch.ethz.ssh2;
02:
03: import java.io.IOException;
04:
05: import ch.ethz.ssh2.sftp.ErrorCodes;
06:
07: /**
08: * Used in combination with the SFTPv3Client. This exception wraps
09: * error messages sent by the SFTP server.
10: *
11: * @author Christian Plattner, plattner@inf.ethz.ch
12: * @version $Id: SFTPException.java,v 1.6 2006/08/18 22:26:35 cplattne Exp $
13: */
14:
15: public class SFTPException extends IOException {
16: private static final long serialVersionUID = 578654644222421811L;
17:
18: private final String sftpErrorMessage;
19: private final int sftpErrorCode;
20:
21: private static String constructMessage(String s, int errorCode) {
22: String[] detail = ErrorCodes.getDescription(errorCode);
23:
24: if (detail == null)
25: return s + " (UNKNOW SFTP ERROR CODE)";
26:
27: return s + " (" + detail[0] + ": " + detail[1] + ")";
28: }
29:
30: SFTPException(String msg, int errorCode) {
31: super (constructMessage(msg, errorCode));
32: sftpErrorMessage = msg;
33: sftpErrorCode = errorCode;
34: }
35:
36: /**
37: * Get the error message sent by the server. Often, this
38: * message does not help a lot (e.g., "failure").
39: *
40: * @return the plain string as sent by the server.
41: */
42: public String getServerErrorMessage() {
43: return sftpErrorMessage;
44: }
45:
46: /**
47: * Get the error code sent by the server.
48: *
49: * @return an error code as defined in the SFTP specs.
50: */
51: public int getServerErrorCode() {
52: return sftpErrorCode;
53: }
54:
55: /**
56: * Get the symbolic name of the error code as given in the SFTP specs.
57: *
58: * @return e.g., "SSH_FX_INVALID_FILENAME".
59: */
60: public String getServerErrorCodeSymbol() {
61: String[] detail = ErrorCodes.getDescription(sftpErrorCode);
62:
63: if (detail == null)
64: return "UNKNOW SFTP ERROR CODE " + sftpErrorCode;
65:
66: return detail[0];
67: }
68:
69: /**
70: * Get the description of the error code as given in the SFTP specs.
71: *
72: * @return e.g., "The filename is not valid."
73: */
74: public String getServerErrorCodeVerbose() {
75: String[] detail = ErrorCodes.getDescription(sftpErrorCode);
76:
77: if (detail == null)
78: return "The error code " + sftpErrorCode + " is unknown.";
79:
80: return detail[1];
81: }
82: }
|