Discussion:
[JSch-users] Problem transferring files larger than 4GB via SFTP
Nicolas Kukolja
2014-02-19 12:07:59 UTC
Permalink
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Hi,</div>

<div>&nbsp;</div>

<div>I am implementing a java application that transfers (large) files to an ftp-server, using sftp (JSch).</div>

<div>&nbsp;</div>

<div>Everything works fine so far with small files. But if a file is larger, the transfer hangs always at about 4GB - 4,1GB and doesn&#39;t move on.</div>

<div>After 10 minutes, I get an &quot;java.io.IOException: Pipe closed&quot;. The &quot;rekey&quot;-Param (http://www.proftpd.org/docs/contrib/mod_sftp.html#SFTPRekey) of the server is configured to 500MB, and the key exchange seems to work fine, as the server log tells me.</div>

<div>&nbsp;</div>

<div>Does anyone have a suggestion, what I am doing wrong?</div>

<div>If you need any more information, please give me a hint...</div>

<div>&nbsp;</div>

<div>
<div>
<div>Kind regards,</div>

<div>Nicolas</div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>&nbsp;</div>
</div>
</div>

<div>Environment:</div>

<div>Client:</div>

<div>- Windows 2008 Server</div>

<div>- Java 1.6.0_45 x64</div>

<div>- Java application using JSch 0.1.50.jar</div>

<div>&nbsp;</div>

<div>Server:</div>

<div>- Solaris 10</div>

<div>- FTP-Server: http://www.proftpd.org</div>

<div>&nbsp;</div>

<div>&nbsp;
<div>&nbsp;</div>

<div>My connect-method:</div>

<div>
<div>&nbsp;&nbsp; public boolean connect( Long orderId )<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.jSch = new JSch();</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.info( &quot;[Order:&quot; + orderId + &quot;] Connecting to SFTP-Server: &quot; + this.username + &quot;:&quot; + this.password + &quot;@&quot; + this.host + &quot;:&quot; + this.port );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // create session<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpSession = this.jSch.getSession( this.username, this.host, this.port );</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // build config<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hashtable&lt;String,String&gt; config = new Hashtable&lt;String,String&gt;();<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.put( &quot;StrictHostKeyChecking&quot;, &quot;no&quot; );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpSession.setConfig( config );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpSession.setPassword( this.password );</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // establish connection<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpSession.connect();</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpChannel = ( ChannelSftp ) this.sftpSession.openChannel( &quot;sftp&quot; );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpChannel.connect();</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.info( &quot;[Order:&quot; + orderId + &quot;] Current directory on SFTP-Server (pwd): &quot; + this.sftpChannel.pwd() );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( this.ftpSubdir != null &amp;&amp; this.ftpSubdir.length() &gt; 0 )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.info( &quot;[Order:&quot; + orderId + &quot;] Changing to subdirectory on SFTP-Server (cd): &quot; + this.ftpSubdir );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.sftpChannel.cd( this.ftpSubdir );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.info( &quot;[Order:&quot; + orderId + &quot;] Current directory on SFTP-Server (pwd): &quot; + this.sftpChannel.pwd() );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch( JSchException e )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.error( &quot;[Order:&quot; + orderId + &quot;] Error connecting to SFTP-Server... (uri: &#39;&quot; + this.sftpUri + &quot;&#39;)&quot;, e );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch( SftpException e )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.error( &quot;[Order:&quot; + orderId + &quot;] Error connecting to SFTP-Server... (uri: &#39;&quot; + this.sftpUri + &quot;&#39;)&quot;, e );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.sftpChannel.isConnected();<br/>
&nbsp;&nbsp; }</div>

<div>&nbsp;</div>

<div>My upload-method:</div>

<div>
<div>&nbsp;&nbsp; public void uploadSynchronized( String source, String target, Long filesize, Long orderId )<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long overallFilesize = filesize == null ? 0 : filesize;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long overallUploadedBytes = 0;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long uploadedBytes = 0;</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( !checkIfFileExists( source ) )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputStream tOut = this.sftpChannel.put( target );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileInputStream in = new FileInputStream( source );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] bytes = new byte[ this.chunkSize ];<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int count = in.read( bytes );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while( count != -1 &amp;&amp; count &lt;= this.chunkSize &amp;&amp; !this.abort )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tOut.write( bytes, 0, count );</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uploadedBytes = uploadedBytes + this.chunkSize;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( uploadedBytes &gt;= BYTES_TO_LOG )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; overallUploadedBytes = overallUploadedBytes + uploadedBytes;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uploadedBytes = 0;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.info( &quot;[Order:&quot; + orderId + &quot;] &quot; + overallUploadedBytes / MEGA_BYTE + &quot;MB of &quot; + overallFilesize / MEGA_BYTE<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + &quot;MB uploaded (source: &#39;&quot; + source + &quot;&#39;, target: &#39;&quot; + target + &quot;&#39;)&quot; );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = in.read( bytes );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in.close();<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tOut.close();<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.success = false;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.error( &quot;[Order:&quot; + orderId + &quot;] Error uploading file... (source: &#39;&quot; + source + &quot;&#39;, target: &#39;&quot; + target<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + &quot;&#39;): File already exists on SFTP-Server&quot; );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch( IOException e )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.success = false;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.error( &quot;[Order:&quot; + orderId + &quot;] Error uploading file... (source: &#39;&quot; + source + &quot;&#39;, target: &#39;&quot; + target + &quot;&#39;)&quot;, e );</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch( SftpException e )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.success = false;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.error( &quot;[Order:&quot; + orderId + &quot;] Error uploading file... (source: &#39;&quot; + source + &quot;&#39;, target: &#39;&quot; + target + &quot;&#39;)&quot;, e );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch( Exception e )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.success = false;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.error( &quot;[Order:&quot; + orderId + &quot;] Error uploading file... (source: &#39;&quot; + source + &quot;&#39;, target: &#39;&quot; + target + &quot;&#39;)&quot;, e );<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp; }</div>
</div>
</div>
</div></div></body></html>
Atsuhiko Yamanaka
2014-02-20 05:08:28 UTC
Permalink
Hi,

+-From: "Nicolas Kukolja" <cool-***@web.de> --
|_Date: Wed, 19 Feb 2014 13:07:59 +0100 ____________
|
|Everything works fine so far with small files.
|But if a file is larger, the transfer hangs always at
|about 4GB - 4,1GB and doesn't move on.
...
|Server:
|- Solaris 10
|- FTP-Server: http://www.proftpd.org

Please try http://www.jcraft.com/jsch/jsch-0.1.51-rc8.zip


Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk

Loading...