in deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ssh/sftp/SftpBuildProcessAdapter.java [38:95]
public BuildFinishedStatus runProcess() {
final String escapedRemotePath;
Session session = null;
JSch.setLogger(new JSchBuildLogger(myLogger));
try {
escapedRemotePath = mySessionProvider.getRemotePath();
session = mySessionProvider.getSession();
if (isInterrupted()) return BuildFinishedStatus.FINISHED_FAILED;
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
if (StringUtil.isNotEmpty(escapedRemotePath)) {
createRemotePath(channel, escapedRemotePath);
channel.cd(escapedRemotePath);
}
myLogger.message("Starting upload via SFTP to " + mySessionProvider.getSessionString());
final String baseDir = channel.pwd();
for (ArtifactsCollection artifactsCollection : myArtifacts) {
int count = 0;
for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) {
checkIsInterrupted();
final File source = fileStringEntry.getKey();
final String value = fileStringEntry.getValue();
final String destinationPath = "".equals(value) ? "." : value;
createRemotePath(channel, destinationPath);
LOG.debug("Transferring [" + source.getAbsolutePath() + "] to [" + destinationPath + "] under [" + baseDir + "]");
channel.put(source.getAbsolutePath(), destinationPath);
LOG.debug("done transferring [" + source.getAbsolutePath() + "]");
count++;
}
myLogger.message("Uploaded [" + count + "] files for [" + artifactsCollection.getSourcePath() + "] pattern");
}
channel.disconnect();
return BuildFinishedStatus.FINISHED_SUCCESS;
} catch (UploadInterruptedException e) {
myLogger.warning("SFTP upload interrupted.");
return BuildFinishedStatus.FINISHED_FAILED;
} catch (JSchException e) {
DeployerAgentUtils.logBuildProblem(myLogger, e.getMessage());
LOG.warnAndDebugDetails("Error executing SFTP command", e);
return BuildFinishedStatus.FINISHED_FAILED;
} catch (SftpException e) {
DeployerAgentUtils.logBuildProblem(myLogger, e.getMessage());
LOG.warnAndDebugDetails("Error executing SFTP command", e);
return BuildFinishedStatus.FINISHED_FAILED;
} finally {
if (session != null) {
session.disconnect();
}
JSch.setLogger(null);
}
}