You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Atsuhiko Yamanaka <ym...@jcraft.com> on 2005/09/05 17:59:37 UTC

a problem on scptask for huge files bigger than 2GB.

Hi,

It seems there is a problem in transfering huge files bigger than
2GB by using scptask, because, in its implementation, the file size
has been handled as 'int' instead of 'long'.  That has come from
my fault in examples included in jsch lib.  I'll post a fix here.


Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
4-1 OHMACHI 1-CHOME AOBA-KU,
SENDAI, MIYAGI 980-0804 Japan.
Tel +81-22-723-2150
    +1-415-578-3454
Fax +81-22-224-8773
Skype callto://jcraft/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: a problem on scptask for huge files bigger than 2GB.

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 6 Sep 2005, Atsuhiko Yamanaka <ym...@jcraft.com> wrote:

> I'll post a fix here.

Something like the patch below?

Cheers

        Stefan

Index: src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java
===================================================================
--- src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java	(revision 279047)
+++ src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java	(working copy)
@@ -157,7 +157,7 @@
      */
     protected void logStats(long timeStarted,
                              long timeEnded,
-                             int totalLength) {
+                             long totalLength) {
         double duration = (timeEnded - timeStarted) / 1000.0;
         NumberFormat format = NumberFormat.getNumberInstance();
         format.setMaximumFractionDigits(2);
@@ -184,7 +184,7 @@
      * @param percentTransmitted the current percent transmitted
      * @return the percent that the file is of the total
      */
-    protected final int trackProgress(int filesize, int totalLength,
+    protected final int trackProgress(long filesize, long totalLength,
                                       int percentTransmitted) {
 
         int percent = (int) Math.round(Math.floor((totalLength
Index: src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
===================================================================
--- src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java	(revision 279047)
+++ src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java	(working copy)
@@ -197,7 +197,7 @@
                                    InputStream in,
                                    OutputStream out) throws IOException {
         // send "C0644 filesize filename", where filename should not include '/'
-        int filesize = (int) localFile.length();
+        long filesize = localFile.length();
         String command = "C0644 " + filesize + " ";
         command += localFile.getName();
         command += "\n";
@@ -211,13 +211,13 @@
         FileInputStream fis = new FileInputStream(localFile);
         byte[] buf = new byte[BUFFER_SIZE];
         long startTime = System.currentTimeMillis();
-        int totalLength = 0;
+        long 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;
+        long initFilesize = filesize;
         int percentTransmitted = 0;
 
         try {
Index: src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
===================================================================
--- src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java	(revision 279047)
+++ src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java	(working copy)
@@ -163,7 +163,7 @@
         int end = serverResponse.indexOf(" ", start + 1);
         start = end + 1;
         end = serverResponse.indexOf(" ", start + 1);
-        int filesize = Integer.parseInt(serverResponse.substring(start, end));
+        long filesize = Long.parseLong(serverResponse.substring(start, end));
         String filename = serverResponse.substring(end + 1);
         log("Receiving: " + filename + " : " + filesize);
         File transferFile = (localFile.isDirectory())
@@ -175,7 +175,7 @@
     }
 
     private void fetchFile(File localFile,
-                            int filesize,
+                            long filesize,
                             OutputStream out,
                             InputStream in) throws IOException {
         byte[] buf = new byte[BUFFER_SIZE];
@@ -184,20 +184,21 @@
         // read a content of lfile
         FileOutputStream fos = new FileOutputStream(localFile);
         int length;
-        int totalLength = 0;
+        long 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;
+        long initFilesize = filesize;
         int percentTransmitted = 0;
 
         try {
             while (true) {
                 length = in.read(buf, 0,
-                        (buf.length < filesize) ? buf.length : filesize);
+                                 (BUFFER_SIZE < filesize) ? BUFFER_SIZE 
+                                                          : (int) filesize);
                 if (length < 0) {
                     throw new EOFException("Unexpected end of stream.");
                 }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org