Bug 47552 - scp task should support compression
Summary: scp task should support compression
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.7.1
Hardware: All Mac OS X 10.4
: P2 enhancement (vote)
Target Milestone: 1.9.8
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-20 20:42 UTC by Damjan Perenic
Modified: 2016-05-23 04:03 UTC (History)
1 user (show)



Attachments
Patch to add compression option to Ant scp task (8.58 KB, patch)
2016-04-21 19:16 UTC, matthew.yanos
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Damjan Perenic 2009-07-20 20:42:48 UTC
Currently there is no way to compress data on the fly with scp task.

My build produces over 90MB of highly compressable files which are then uploaded sometimes over slow link. Compression would help a lot.

I can exec scp with -C parameter, but that it not cross platform. It will not work on Windows, unless some kind of scp is present in path.
Comment 1 matthew.yanos 2016-04-21 19:16:01 UTC
Created attachment 33791 [details]
Patch to add compression option to Ant scp task

This patch adds the currently unavailable compression option to the Ant scp task. On the command line, it's just adding a "-C" to the parameters of the "scp" command. This fix exposes this parameter up to the level of the Ant task wrapper with the boolean "compressed" parameter.

All modifications are to classes in the org.apache.tools.ant.taskdefs.optional.ssh package.

A private boolean flag to indicate whether compression should be used is added to AbstractSshMessage, mutable only via a new constructor which overloads the previous constructor by adding the new parameter. The flag's value is visible via a new accessor method, getCompressed(). The AbstractSshMessage class is extended by both ScpFromMessage and ScpToMessage. Both ScpFromMessage and ScpToMessage contain execute() methods. New overloaded constructors have been added to both ScpFromMessage and the ScpToMessage to include the boolean flag to use compression. These flags are passed into the call to
 the parent AbstractSshMessage class's newly added constructors.

In ScpFromMessage, the execute() method is where the call to "scp" with its various command line parameters is made. This has been altered to check the parent class's getCompressed() accessor method. If true, the "-C" command line parameter is appended to the command String.

The ScpToMessage class's execute() method calls one of two other private member methods to enact the "scp" command: doSingleTransfer() and doMultipleTransfers(), depending on whether either a single file or a list of files has been specified. In both of these methods, the parent class's getCompressed() accessor method is checked. If true, the "-C" command line parameter is appended to the command String.

Finally, the Scp class, representing the actual ant task, was modified to include a private boolean flag to indicate that compression should be used. Its value is defaulted to false, and the class has been modified to include a standard mutator method for it. This new boolean flag is the parameter by which the compression option can be used. A call to the An
t task using the new compression option would look like the following:
<scp file="myfile.txt" todir="user@somehost:/home/chuck" password="password" compression="true" />
Comment 2 Stefan Bodewig 2016-05-22 15:59:13 UTC
Thanks a lot Matthew

unfortunately the patch didn't apply cleanly because of other changes made to scp in the meantime. I've tried to adapt it, the result is commit 3fe363e - currently inside a branch. See for example https://github.com/apache/ant/commit/3fe363e2120342f6de2b219c3bd74efe9aea2803

Do you think I've adapted it correctly or did I miss anything?
Comment 3 matthew.yanos 2016-05-22 17:40:45 UTC
Yes, I reviewed it, and your adaptation looks correct to me. I didn't notice any missed modifications. I very much appreciate you doing the manual merge work to include this. Thanks!
Comment 4 Stefan Bodewig 2016-05-23 04:03:40 UTC
Thank you.

I've merged the branches, the feature will be available inn 1.9.8 and 1.10.0.