Throw a SCPRemoteException when an error occurs on the remote server. SCPRemoteException contains the error message returned from the remote server.

This commit is contained in:
gaddiej
2015-10-24 13:54:49 +00:00
parent d520585a09
commit 10f8645ecd
3 changed files with 19 additions and 3 deletions

View File

@@ -123,7 +123,7 @@ public final class SCPDownloadClient extends AbstractSCPClient {
case (char) 1:
case (char) 2:
throw new SCPException("Remote SCP command returned error: " + msg.substring(1));
throw new SCPRemoteException("Remote SCP command returned error: " + msg.substring(1), msg.substring(1));
default:
final String err = "Unrecognized message: `" + msg + "`";
@@ -202,4 +202,4 @@ public final class SCPDownloadClient extends AbstractSCPClient {
return parts;
}
}
}

View File

@@ -69,7 +69,8 @@ class SCPEngine {
return;
case 1: // Warning? not
case 2:
throw new SCPException("Remote SCP command had error: " + readMessage());
final String remoteMessage = readMessage();
throw new SCPRemoteException("Remote SCP command had error: " + remoteMessage, remoteMessage);
default:
throw new SCPException("Received unknown response code");
}

View File

@@ -0,0 +1,15 @@
package net.schmizz.sshj.xfer.scp;
public class SCPRemoteException extends SCPException
{
private final String remoteMessage;
public SCPRemoteException(String message, String remoteMessage) {
super(message);
this.remoteMessage = remoteMessage;
}
public String getRemoteMessage() {
return remoteMessage;
}
}