private void upload()

in deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ssh/scp/ScpProcessAdapter.java [130:173]


  private void upload(final @NotNull Session session,
                      final @NotNull String escapedRemoteBase,
                      final @NotNull List<ArtifactsCollection> artifacts) throws IOException, JSchException {

    assert session.isConnected();

    // skip empty collections
    if (artifacts.size() == 0) {
      return;
    }

    // exec 'scp -rt <remoteBase>' remotely
    final String command = "scp -rt " + (StringUtil.isEmptyOrSpaces(escapedRemoteBase) ? "." : escapedRemoteBase);
    final ChannelExec execChannel = (ChannelExec) session.openChannel("exec");
    execChannel.setCommand(command);

    // get I/O streams for remote scp
    final OutputStream out = execChannel.getOutputStream();
    final InputStream in = execChannel.getInputStream();

    execChannel.connect();
    ScpExecUtil.checkScpAck(in);

    try {
      for (ArtifactsCollection artifactCollection : artifacts) {
        int count = 0;
        for (Map.Entry<File, String> filePathEntry : artifactCollection.getFilePathMap().entrySet()) {
          final File source = filePathEntry.getKey();
          final String destination = filePathEntry.getValue();
          final ScpOperation operationChain = ScpOperationBuilder.getCopyFileOperation(source, destination);
          myInternalLog.debug("Transferring [" + source.getAbsolutePath() + "] to [" + destination + "]");
          checkIsInterrupted();
          operationChain.execute(out, in);
          myInternalLog.debug("done transferring [" + source.getAbsolutePath() + "]");
          count++;
        }
        myLogger.message("Uploaded [" + count + "] files for [" + artifactCollection.getSourcePath() + "] pattern");
      }
    } finally {
      FileUtil.close(out);
      FileUtil.close(in);
      execChannel.disconnect();
    }
  }