GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add configurable file transfer client with SCP/SFTP support by diegolovison · Pull Request #784 · Hyperfoil/Hyperfoil

Conversation

@diegolovison

@diegolovison diegolovison commented May 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Add a configurable file transfer client with SCP/SFTP support

The default behavior will be scp with array, but the user is allowed to change to sftp via -Dio.hyperfoil.file.transfer.client=sftp

This can boost the copy by around 11x

Here is the raw data and ratio.

Files scp with array (Baseline) sftp
1 304 ms 15 ms (20.27x faster)
10 540 ms 50 ms (10.80x faster)
100 3442 ms 296 ms (11.63x faster)
1000 33474 ms 2760 ms (12.13x faster)

Reproducer:

mvn test -Dtest=FileTransferPerformanceTest -Dio.hyperfoil.file.transfer.client=scp
mvn test -Dtest=FileTransferPerformanceTest -Dio.hyperfoil.file.transfer.client=sftp

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@diegolovison
diegolovison force-pushed the sftp_2 branch from 095117b to ce1aef5 Compare May 12, 2026 17:26
stalep
stalep requested changes Jun 4, 2026
View reviewed changes

@stalep stalep left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on the performance improvement - the SCP vs SFTP numbers are compelling, especially for multi-file transfers.

A few suggestions on the design and two bugs I spotted. The main design suggestion is to make FileTransfer an abstract class instead of using delegation through IFileTransfer. This eliminates the interface (whose I prefix is not idiomatic Java), removes the delegation boilerplate, and lets the factory logic live in a static method with a proper return type.

I also noticed a bug in the SFTP single-file upload path and a test bug with missing cleanup between iterations - details in the inline comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread clustering/src/main/java/io/hyperfoil/deploy/ssh/FileTransfer.java
Comment on lines +20 to +110
public class FileTransfer implements AutoCloseable {

private static final Logger log = LogManager.getLogger(FileTransfer.class);

private IFileTransfer client;

FileTransfer(ClientSession session) throws Exception {
String fileTransferClient = Properties.get(Properties.FILE_TRANSFER_CLIENT, "scp");
log.info("Using {} protocol for file transfer", fileTransferClient);
if ("scp".equals(fileTransferClient)) {
this.client = new Scp(session);
} else if ("sftp".equals(fileTransferClient)) {
this.client = new Sftp(session);
} else {
throw new IllegalArgumentException("Invalid file transfer client. You provided: " + fileTransferClient);
}
}

public void upload(String local, String remote) throws IOException {
this.upload(List.of(local), remote);
}

public void upload(List<String> local, String remote) throws IOException {
this.client.upload(local, remote);
}

@Override
public void close() throws IOException {
this.client.close();
}

private interface IFileTransfer {

void upload(List<String> local, String remote) throws IOException;

void close() throws IOException;
}

private static class Scp implements IFileTransfer {

private ScpClient scpClient;

Scp(ClientSession session) {
this.scpClient = ScpClientCreator.instance().createScpClient(session);
}

@Override
public void upload(List<String> local, String remote) throws IOException {
if (!local.isEmpty()) {
this.scpClient.upload(local.toArray(String[]::new), remote, ScpClient.Option.PreserveAttributes);
}
}

@Override
public void close() {

}
}

private static class Sftp implements IFileTransfer {

private SftpClient sftpClient;

Sftp(ClientSession session) throws Exception {
try {
this.sftpClient = SftpClientFactory.instance().createSftpClient(session);
} catch (IOException e) {
throw new Exception("Problem while creating the Sftp instance", e);
}
}

@Override
public void upload(List<String> local, String remote) throws IOException {
for (String l : local) {
try (InputStream in = new FileInputStream(l);
OutputStream out = sftpClient.write(remote + "/" + new File(l).getName())) {
byte[] buffer = new byte[8192];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
}
}
}

@Override
public void close() throws IOException {
this.sftpClient.close();
}
}
}

@stalep stalep Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: refactor FileTransfer to be an abstract class with a static factory method, eliminating the IFileTransfer interface and the delegation layer.

Benefits:

  • Removes IFileTransfer (and its non-idiomatic I prefix)
  • Scp and Sftp extend FileTransfer directly - no wrapping
  • Factory method returns IOException instead of broad Exception
  • Fields are final
  • SFTP buffer increased to 32KB for better throughput on larger JARs
public abstract class FileTransfer implements AutoCloseable {

   private static final Logger log = LogManager.getLogger(FileTransfer.class);

   public static FileTransfer create(ClientSession session) throws IOException {
      String protocol = Properties.get(Properties.FILE_TRANSFER_CLIENT, "scp");
      log.info("Using {} protocol for file transfer", protocol);
      return switch (protocol) {
         case "scp" -> new Scp(session);
         case "sftp" -> new Sftp(session);
         default -> throw new IllegalArgumentException(
               "Invalid file transfer client. You provided: " + protocol + ". Supported: scp, sftp");
      };
   }

   public void upload(String local, String remote) throws IOException {
      upload(List.of(local), remote);
   }

   public abstract void upload(List<String> local, String remote) throws IOException;

   @Override
   public abstract void close() throws IOException;

   static class Scp extends FileTransfer {

      private final ScpClient scpClient;

      Scp(ClientSession session) {
         this.scpClient = ScpClientCreator.instance().createScpClient(session);
      }

      @Override
      public void upload(List<String> local, String remote) throws IOException {
         if (!local.isEmpty()) {
            this.scpClient.upload(local.toArray(String[]::new), remote, ScpClient.Option.PreserveAttributes);
         }
      }

      @Override
      public void close() {
         // ScpClient has no close method
      }
   }

   static class Sftp extends FileTransfer {

      private final SftpClient sftpClient;

      Sftp(ClientSession session) throws IOException {
         this.sftpClient = SftpClientFactory.instance().createSftpClient(session);
      }

      @Override
      public void upload(List<String> local, String remote) throws IOException {
         for (String l : local) {
            String target = remote + "/" + new File(l).getName();
            try (InputStream in = new FileInputStream(l);
                  OutputStream out = sftpClient.write(target)) {
               byte[] buffer = new byte[32768];
               int len;
               while ((len = in.read(buffer)) != -1) {
                  out.write(buffer, 0, len);
               }
            }
         }
      }

      @Override
      public void close() throws IOException {
         this.sftpClient.close();
      }
   }
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread clustering/src/main/java/io/hyperfoil/deploy/ssh/SshDeployedAgent.java
Comment on lines +103 to +107
try {
this.fileTransfer = new FileTransfer(session);
} catch (Exception e) {
exceptionHandler.accept(new DeploymentException("Failed to initialize file transfer", e));
return;

@stalep stalep Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the factory method approach, this becomes:

      try {
         this.fileTransfer = FileTransfer.create(session);
      } catch (IOException e) {
         exceptionHandler.accept(new DeploymentException("Failed to initialize file transfer", e));
         return;
      }

Narrowing the catch to IOException instead of Exception.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread clustering/src/main/java/io/hyperfoil/deploy/ssh/SshDeployedAgent.java
@@ -205,7 +215,7 @@ public void close() throws IOException {
String filename = log4jConfigurationFile.substring(log4jConfigurationFile.lastIndexOf(File.separatorChar) + 1);

@stalep stalep Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: This passes targetFile which is already a full path including the filename (e.g. /dir/agentlib/log4j2.xml). But FileTransfer.upload(String, String) delegates to upload(List.of(local), remote), and the SFTP implementation does remote + "/" + new File(l).getName() - resulting in /dir/agentlib/log4j2.xml/log4j2.xml.

The SCP path works because the underlying ScpClient.upload(String[], String, Option...) handles single-file-to-file-path correctly.

You need either:

  1. A separate upload method for single-file-to-exact-path (no filename appending), or
  2. Have the SFTP implementation detect whether remote is a directory or a file path

Option 1 is simpler - add a boolean parameter or a separate method name like uploadTo for the exact-path case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test-suite/src/test/java/io/hyperfoil/deploy/ssh/FileTransferTest.java Outdated
Comment on lines +44 to +45
* mvn test -Dtest=FileTransferPerformanceTest -Dio.hyperfoil.file.transfer.client=scp
* mvn test -Dtest=FileTransferPerformanceTest -Dio.hyperfoil.file.transfer.client=sftp

@stalep stalep Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc references the wrong class name.

Should be FileTransferTest instead of FileTransferPerformanceTest.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test-suite/src/test/java/io/hyperfoil/deploy/ssh/FileTransferTest.java Outdated
Comment on lines +108 to +110
for (int fileCount : fileCounts) {
log.info("--- Testing with {} file(s) ---", fileCount);

@stalep stalep Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The remoteDir is not cleaned between iterations. After the 1-file iteration uploads 1 file, the 10-file iteration will find 11 files in remoteDir, causing assertEquals(files.size(), uploadedFileCount) to fail.

Add cleanup at the start of each iteration:

         // Clean remote directory from previous iteration
         try (var files = Files.list(remoteDir)) {
            files.forEach(p -> {
               try {
                  Files.deleteIfExists(p);
               } catch (IOException e) {
                  log.warn("Failed to clean up {}", p, e);
               }
            });
         }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test-suite/src/test/java/io/hyperfoil/deploy/ssh/FileTransferTest.java Outdated
}

private long testFileTransfer(List<String> files) throws Exception {
try (FileTransfer fileTransfer = new FileTransfer(session)) {

@stalep stalep Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the refactor this becomes FileTransfer.create(session).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@franz1981

franz1981 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

@diegolovison this is still valid or #780 is enough and we can close it?
Asking to save others (thanks @stalep to have reviewed it the same!) to review it accidentaly

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@diegolovison

diegolovison commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

@franz1981 Yes. This PR is valid.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@diegolovison
diegolovison force-pushed the sftp_2 branch from 67952b9 to a9122b8 Compare June 8, 2026 11:47
@diegolovison

diegolovison commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

@stalep I decided to keep the inner interface and inner implementation to reduce the surface of the change.
It is ready to review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stalep

stalep commented Jun 9, 2026

Copy link
Copy Markdown
Member

I think this looks good and can be merged as it. I personally do not like the IFileTransfer, but I guess that's a more personal take.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@diegolovison
diegolovison force-pushed the sftp_2 branch from a9122b8 to 74719db Compare June 9, 2026 18:13
@diegolovison
diegolovison force-pushed the sftp_2 branch from 74719db to 0f2fcec Compare October 19, 2026 15:04
@diegolovison
Add configurable file transfer client with SCP/SFTP support
267b6c0
@diegolovison
diegolovison force-pushed the sftp_2 branch from 0f2fcec to 267b6c0 Compare October 19, 2026 21:08
@diegolovison
diegolovison marked this pull request as draft October 20, 2026 13:15
@diegolovison diegolovison added the WIP label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@stalep stalep stalep requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

WIP

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@diegolovison @franz1981 @stalep
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.