bodewig 2004/04/13 04:26:13 Modified: . Tag: ANT_16_BRANCH CONTRIBUTORS docs/manual/OptionalTasks Tag: ANT_16_BRANCH scp.html src/main/org/apache/tools/ant/taskdefs/optional/ssh Tag: ANT_16_BRANCH AbstractSshMessage.java SSHBase.java Scp.java ScpFromMessage.java ScpToMessage.java Log: merge Revision Changes Path No revision No revision 1.1.2.5 +3 -1 ant/CONTRIBUTORS Index: CONTRIBUTORS =================================================================== RCS file: /home/cvs/ant/CONTRIBUTORS,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- CONTRIBUTORS 5 Apr 2004 12:18:25 -0000 1.1.2.4 +++ CONTRIBUTORS 13 Apr 2004 11:26:13 -0000 1.1.2.5 @@ -65,6 +65,7 @@ Holger Engels Ingenonsya France Ingmar Stein +Jack J. Woehr James Duncan Davidson Jan Matèrne Jason Hunter @@ -146,8 +147,9 @@ Phillip Wells Pierre Delisle Pierre Dittgen -Raphael Pierquin R Handerson +Rami Ojares +Raphael Pierquin Richard Evans Rick Beton Robert Anderson No revision No revision 1.7.2.7 +45 -3 ant/docs/manual/OptionalTasks/scp.html Index: scp.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/scp.html,v retrieving revision 1.7.2.6 retrieving revision 1.7.2.7 diff -u -r1.7.2.6 -r1.7.2.7 --- scp.html 9 Feb 2004 22:12:11 -0000 1.7.2.6 +++ scp.html 13 Apr 2004 11:26:13 -0000 1.7.2.7 @@ -21,7 +21,7 @@ in the Ant distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more information. This task has been tested with jsch-0.1.2 to -jsch-0.1.9.</p> +jsch-0.1.14.</p> <h3>Parameters</h3> <table border="1" cellpadding="2" cellspacing="0"> @@ -35,19 +35,54 @@ <td valign="top">The file to copy. This can be a local path or a remote path of the form <i>user[:[EMAIL PROTECTED]:/directory/path</i>. <i>:password</i> can be ommitted if you use key based - authentication or specify the password attribute.</td> + authentication or specify the password attribute. The way remote + path is recognized is whether it contains @ character or not. This + will not work if your localPath contains @ character.</td> <td valign="top" align="center">Yes, unless a nested <code><fileset></code> element is used.</td> </tr> <tr> + <td valign="top">localFile</td> + <td valign="top">This is an alternative to the file attribute. But + this must always point to a local file. The reason this was added + was that when you give file attribute it is treated as remote if + it contains @ character. This character can exist also in local + paths. <em>since Ant 1.6.2</em></td> + <td valign="top" align="center">Alternative to file attribute.</td> + </tr> + <tr> + <td valign="top">remoteFile</td> + <td valign="top">This is an alternative to the file attribute. But + this must always point to a remote file. <em>since Ant 1.6.2</em></td> + <td valign="top" align="center">Alternative to file attribute.</td> + </tr> + <tr> <td valign="top">todir</td> <td valign="top">The directory to copy to. This can be a local path or a remote path of the form <i>user[:[EMAIL PROTECTED]:/directory/path</i>. <i>:password</i> can be ommitted if you use key based - authentication or specify the password attribute.</td> + authentication or specify the password attribute. The way remote + path is recognized is whether it contains @ character or not. This + will not work if your localPath contains @ character.</td> <td valian="top" align="center">Yes</td> </tr> <tr> + <td valign="top">localTodir</td> + <td valign="top">This is an alternative to the todir + attribute. But this must always point to a local directory. The + reason this was added was that when you give todir attribute it is + treated as remote if it contains @ character. This character can + exist also in local paths. <em>since Ant 1.6.2</em></td> + <td valian="top" align="center">Alternative to todir attribute.</td> + </tr> + <tr> + <td valign="top">remoteTodir</td> + <td valign="top">This is an alternative to the todir + attribute. But this must always point to a remote directory. + <em>since Ant 1.6.2</em></td> + <td valian="top" align="center">Alternative to todir attribute.</td> + </tr> + <tr> <td valign="top">port</td> <td valign="top">The port to connect to on the remote host.</td> <td valian="top" align="center">No, defaults to 22.</td> @@ -92,6 +127,13 @@ <td valign="top">Passphrase for your private key.</td> <td valign="top" align="center">Yes, if you are using key based authentication.</td> + </tr> + <tr> + <td valign="top">verbose</td> + <td valign="top">Determines whether SCP outputs verbosely to the + user. Currently this means outputting dots/stars showing the + progress of a file transfer. <em>since Ant 1.6.2</em></td> + <td valign="top" align="center">No; defaults to false.</td> </tr> </table> <h3>Parameters specified as nested elements</h3> No revision No revision 1.4.2.5 +50 -0 ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java Index: AbstractSshMessage.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java,v retrieving revision 1.4.2.4 retrieving revision 1.4.2.5 diff -u -r1.4.2.4 -r1.4.2.5 --- AbstractSshMessage.java 9 Feb 2004 22:12:38 -0000 1.4.2.4 +++ AbstractSshMessage.java 13 Apr 2004 11:26:13 -0000 1.4.2.5 @@ -32,6 +32,7 @@ public abstract class AbstractSshMessage { private Session session; + private boolean verbose; private LogListener listener = new LogListener() { public void log(String message) { // do nothing; @@ -39,6 +40,14 @@ }; public AbstractSshMessage(Session session) { + this(false, session); + } + + /** + * @since Ant 1.6.2 + */ + public AbstractSshMessage(boolean verbose, Session session) { + this.verbose = verbose; this.session = session; } @@ -114,4 +123,45 @@ + " Average Rate: " + format.format(totalLength / duration) + " B/s"); } + + /** + * @since Ant 1.6.2 + */ + protected final boolean getVerbose() { + return verbose; + } + + /* + * Track progress every 10% if 100kb < filesize < 1mb. For larger + * files track progress for every percent transmitted. + */ + protected final int trackProgress(int filesize, int totalLength, + int percentTransmitted) { + + int percent = (int) Math.round(Math.floor((totalLength / + (double)filesize) * 100)); + + if (percent > percentTransmitted) { + if (filesize < 1048576) { + if (percent % 10 == 0) { + if (percent == 100) { + System.out.println(" 100%"); + } else { + System.out.print("*"); + } + } + } else { + if (percent == 50) { + System.out.println(" 50%"); + } else if (percent == 100) { + System.out.println(" 100%"); + } else { + System.out.print("."); + } + } + } + + return percent; + } + } 1.5.2.6 +15 -0 ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java Index: SSHBase.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java,v retrieving revision 1.5.2.5 retrieving revision 1.5.2.6 diff -u -r1.5.2.5 -r1.5.2.6 --- SSHBase.java 9 Mar 2004 17:01:53 -0000 1.5.2.5 +++ SSHBase.java 13 Apr 2004 11:26:13 -0000 1.5.2.6 @@ -40,6 +40,7 @@ private String knownHosts; private int port = SSH_PORT; private boolean failOnError = true; + private boolean verbose; private SSHUserInfo userInfo; /** @@ -69,6 +70,20 @@ public boolean getFailonerror() { return failOnError; + } + + /** + * @since Ant 1.6.2 + */ + public void setVerbose(boolean failure) { + verbose = failure; + } + + /** + * @since Ant 1.6.2 + */ + public boolean getVerbose() { + return verbose; } /** 1.9.2.6 +48 -9 ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java Index: Scp.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java,v retrieving revision 1.9.2.5 retrieving revision 1.9.2.6 diff -u -r1.9.2.5 -r1.9.2.6 --- Scp.java 9 Mar 2004 17:01:53 -0000 1.9.2.5 +++ Scp.java 13 Apr 2004 11:26:13 -0000 1.9.2.6 @@ -43,6 +43,7 @@ private String fromUri; private String toUri; private List fileSets = null; + private boolean isFromRemote, isToRemote; /** * Sets the file to be transferred. This can either be a remote @@ -55,6 +56,7 @@ */ public void setFile(String aFromUri) { this.fromUri = aFromUri; + this.isFromRemote = isRemoteUri(this.fromUri); } /** @@ -68,9 +70,50 @@ */ public void setTodir(String aToUri) { this.toUri = aToUri; + this.isToRemote = isRemoteUri(this.toUri); } + /** + * Similiar to [EMAIL PROTECTED] #setFile setFile} but explicitly states that + * the file is a local file. This is the only way to specify a + * local file with a @ character. + * @since Ant 1.6.2 + */ + public void setLocalFile(String aFromUri) { + this.fromUri = aFromUri; + this.isFromRemote = false; + } + + /** + * Similiar to [EMAIL PROTECTED] #setFile setFile} but explicitly states that + * the file is a remote file. + * @since Ant 1.6.2 + */ + public void setRemoteFile(String aFromUri) { + this.fromUri = aFromUri; + this.isFromRemote = true; + } + + /** + * Similiar to [EMAIL PROTECTED] #setTodir setTodir} but explicitly states + * that the directory is a local. This is the only way to specify + * a local directory with a @ character. + * @since Ant 1.6.2 + */ + public void setLocalTodir(String aToUri) { + this.toUri = aToUri; + this.isToRemote = false; + } + /** + * Similiar to [EMAIL PROTECTED] #setTodir setTodir} but explicitly states + * that the directory is a remote. + * @since Ant 1.6.2 + */ + public void setRemoteTodir(String aToUri) { + this.toUri = aToUri; + this.isToRemote = true; + } /** * Adds a FileSet tranfer to remote host. NOTE: Either @@ -102,11 +145,6 @@ + "FileSet is required."); } - boolean isFromRemote = false; - if (fromUri != null) { - isFromRemote = isRemoteUri(fromUri); - } - boolean isToRemote = isRemoteUri(toUri); try { if (isFromRemote && !isToRemote) { download(fromUri, toUri); @@ -140,7 +178,7 @@ try { session = openSession(); ScpFromMessage message = - new ScpFromMessage(session, file, + new ScpFromMessage(getVerbose(), session, file, getProject().resolveFile(toPath), fromSshUri.endsWith("*")); log("Receiving file: " + file); @@ -169,7 +207,8 @@ } if (!list.isEmpty()) { session = openSession(); - ScpToMessage message = new ScpToMessage(session, list, file); + ScpToMessage message = new ScpToMessage(getVerbose(), session, + list, file); message.setLogListener(this); message.execute(); } @@ -188,8 +227,8 @@ try { session = openSession(); ScpToMessage message = - new ScpToMessage(session, getProject().resolveFile(fromPath), - file); + new ScpToMessage(getVerbose(), session, + getProject().resolveFile(fromPath), file); message.setLogListener(this); message.execute(); } finally { 1.4.2.4 +29 -4 ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java Index: ScpFromMessage.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java,v retrieving revision 1.4.2.3 retrieving revision 1.4.2.4 diff -u -r1.4.2.3 -r1.4.2.4 --- ScpFromMessage.java 9 Feb 2004 22:12:38 -0000 1.4.2.3 +++ ScpFromMessage.java 13 Apr 2004 11:26:13 -0000 1.4.2.4 @@ -38,14 +38,25 @@ private File localFile; private boolean isRecursive = false; + /** + * @since Ant 1.6.2 + */ + public ScpFromMessage(boolean verbose, + Session session, + String aRemoteFile, + File aLocalFile, + boolean recursive) { + super(verbose, session); + this.remoteFile = aRemoteFile; + this.localFile = aLocalFile; + this.isRecursive = recursive; + } + public ScpFromMessage(Session session, String aRemoteFile, File aLocalFile, boolean recursive) { - super(session); - this.remoteFile = aRemoteFile; - this.localFile = aLocalFile; - this.isRecursive = recursive; + this(false, session, aRemoteFile, aLocalFile, recursive); } public void execute() throws IOException, JSchException { @@ -153,6 +164,14 @@ int length; int totalLength = 0; long startTime = System.currentTimeMillis(); + + // only track progress for files larger than 100kb in verbose mode + boolean trackProgress = getVerbose() && filesize > 102400; + // since filesize keeps on decreasing we have to store the + // initial filesize + int initFilesize = filesize; + int percentTransmitted = 0; + try { while (true) { length = in.read(buf, 0, @@ -165,6 +184,12 @@ totalLength += length; if (filesize == 0) { break; + } + + if (trackProgress) { + percentTransmitted = trackProgress(initFilesize, + totalLength, + percentTransmitted); } } } finally { 1.4.2.5 +48 -6 ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java Index: ScpToMessage.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java,v retrieving revision 1.4.2.4 retrieving revision 1.4.2.5 diff -u -r1.4.2.4 -r1.4.2.5 --- ScpToMessage.java 9 Feb 2004 22:12:38 -0000 1.4.2.4 +++ ScpToMessage.java 13 Apr 2004 11:26:13 -0000 1.4.2.5 @@ -36,22 +36,50 @@ private String remotePath; private List directoryList; - public ScpToMessage(Session session, + /** + * @since Ant 1.6.2 + */ + public ScpToMessage(boolean verbose, + Session session, File aLocalFile, String aRemotePath) { - super(session); + this(verbose, session, aRemotePath); this.localFile = aLocalFile; + } + + /** + * @since Ant 1.6.2 + */ + public ScpToMessage(boolean verbose, + Session session, + List aDirectoryList, + String aRemotePath) { + this(verbose, session, aRemotePath); + + this.directoryList = aDirectoryList; + } + + /** + * @since Ant 1.6.2 + */ + private ScpToMessage(boolean verbose, + Session session, + String aRemotePath) { + super(verbose, session); this.remotePath = aRemotePath; } public ScpToMessage(Session session, + File aLocalFile, + String aRemotePath) { + this(false, session, aLocalFile, aRemotePath); + } + + public ScpToMessage(Session session, List aDirectoryList, String aRemotePath) { - super(session); - - this.directoryList = aDirectoryList; - this.remotePath = aRemotePath; + this(false, session, aDirectoryList, aRemotePath); } public void execute() throws IOException, JSchException { @@ -150,6 +178,14 @@ byte[] buf = new byte[BUFFER_SIZE]; long startTime = System.currentTimeMillis(); int totalLength = 0; + + // only track progress for files larger than 100kb in verbose mode + boolean trackProgress = getVerbose() && filesize > 102400; + // since filesize keeps on decreasing we have to store the + // initial filesize + int initFilesize = filesize; + int percentTransmitted = 0; + try { log("Sending: " + localFile.getName() + " : " + localFile.length()); while (true) { @@ -159,6 +195,12 @@ } out.write(buf, 0, len); totalLength += len; + + if (trackProgress) { + percentTransmitted = trackProgress(initFilesize, + totalLength, + percentTransmitted); + } } out.flush(); sendAck(out);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]