* @throws RemoteScpException
* in case of problems on the target system (connection ok)
*/
public void put(String localFile, String remoteTargetDir, String remoteTargetName, String mode)
throws IOException, RemoteScpException {
ChannelExec channel = null;
if ((localFile == null) || (remoteTargetName == null)) {
throw new IllegalArgumentException("Null argument.");
}
if (mode != null) {
if (mode.length() != MODE_LENGTH) {
throw new IllegalArgumentException("Invalid mode.");
}
for (int i = 0; i < mode.length(); i++) {
if (!Character.isDigit(mode.charAt(i))) {
throw new IllegalArgumentException("Invalid mode.");
}
}
}
String cmd = "scp -t ";
if (mode != null) {
cmd = cmd + "-p ";
}
if (remoteTargetDir != null && remoteTargetDir.length() > 0) {
cmd = cmd + "-d " + remoteTargetDir;
}
try {
channel = getExecChannel();
channel.setCommand(cmd);
sendFile(channel, localFile, remoteTargetName, mode);
channel.disconnect();
} catch (JSchException e) {
if (channel != null) {
channel.disconnect();
}
throw (IOException) new IOException("Error during SCP transfer." + e.getMessage())
.initCause(e);
}
}