title: Why is the SSHJ maximum write size 32KB?
body: <p>I have been using SSHJ to write files to my remote SFTP server. The current set up is I have a Spring Batch ItemWriter that writes chunks of data arbitrarily to a file. Jsch does not support this feature as if the chunks come in out of order then the file is corrupted as the chunks got written out of order, this is why I have turned to SSHJ.</p>
  <p>The problem comes in with the size of the data chunks. Currently any size above 32KB breaks the transfer instantly with the following exception.</p>
  <p><code>net.schmizz.sshj.connection.ConnectionException: Timeout when trying to expand the window size</code></p>
  <p>My goal is to maximize the throughput of my file transfer as much as possible and generally this done is by increasing the window size or the packet size. The issue is despite increasing both on the client and Socket I get the following exception</p>
  <p>After reading the <a href="https://www.rfc-editor.org/rfc/rfc4254.html" rel="nofollow noreferrer">SSH RFC</a> it states that the maximum window size can be up to `2^32-1 roughly equal to 4.29GB. So if I set the buffer size and the window size to be the max possible 2^32-1 the transfer should work but the exception above comes up.</p>
  <p>Here is the current client configuration</p>
  <pre><code>    SSHClient sshClient = new SSHClient();
      Connection conn = sshClient.getConnection();
      conn.setWindowSize(dataChunkSize);
      sshClient.addHostKeyVerifier(new PromiscuousVerifier());
      sshClient.connect(destCredUri[0], Integer.parseInt(destCredUri[1]));
      Socket socket = sshClient.getSocket();
      socket.setTcpNoDelay(true);
      socket.setKeepAlive(true);
      socket.setSendBufferSize(Math.toIntExact(dataChunkSize));
      socket.setReceiveBufferSize(Math.toIntExact(dataChunkSize));
  </code></pre>
  <p>How can I increase the chunk size above 32KB? On the side any advice on maximizing throughput over SFTP would be amazing.</p>
  <p>Thank you very much in advance.</p>