in wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagon.java [266:342]
public void fillOutputData(OutputData outputData) throws TransferFailedException {
Resource resource = outputData.getResource();
String basedir = getRepository().getBasedir();
String path = getPath(basedir, resource.getName());
String dir = ScpHelper.getResourceDirectory(resource.getName());
try {
sshTool.createRemoteDirectories(
getPath(basedir, dir), getRepository().getPermissions());
} catch (CommandExecutionException e) {
fireTransferError(resource, e, TransferEvent.REQUEST_PUT);
throw new TransferFailedException(e.getMessage(), e);
}
String octalMode = getOctalMode(getRepository().getPermissions());
// exec 'scp -p -t rfile' remotely
String command = "scp";
if (octalMode != null) {
command += " -p";
}
command += " -t \"" + path + "\"";
fireTransferDebug("Executing command: " + command);
String resourceName = resource.getName();
OutputStream out = null;
try {
channel = (ChannelExec) session.openChannel(EXEC_CHANNEL);
channel.setCommand(command);
// get I/O streams for remote scp
out = channel.getOutputStream();
outputData.setOutputStream(out);
channelInputStream = channel.getInputStream();
channel.connect();
checkAck(channelInputStream);
// send "C0644 filesize filename", where filename should not include '/'
long filesize = resource.getContentLength();
String mode = octalMode == null ? "0644" : octalMode;
command = "C" + mode + " " + filesize + " ";
if (resourceName.lastIndexOf(ScpHelper.PATH_SEPARATOR) > 0) {
command += resourceName.substring(resourceName.lastIndexOf(ScpHelper.PATH_SEPARATOR) + 1);
} else {
command += resourceName;
}
command += "\n";
out.write(command.getBytes());
out.flush();
checkAck(channelInputStream);
} catch (JSchException e) {
fireTransferError(resource, e, TransferEvent.REQUEST_PUT);
String msg = "Error occurred while deploying '" + resourceName + "' to remote repository: "
+ getRepository().getUrl() + ": " + e.getMessage();
throw new TransferFailedException(msg, e);
} catch (IOException e) {
handleIOException(resource, e);
}
}