mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Benovich <m...@hostedftp.com>
Subject Trouble with SFTP resume upload
Date Sat, 14 Jun 2014 11:19:24 GMT

I very recently began using SSHD to run my own SFTP server. I am running
version 0.11.0 and I am having trouble resuming uploads with FileZilla as
my client.

The problem I am having is with the "write" method inside
org.apache.sshd.server.sftp.SftpSubsystem (code shown below).

When the resume upload begins, offset is some value greater than zero and
output is null, so we call file.createOutputStream(offset) and append 16K
bytes of data to the end of the file.

The issue is that because outputPos = 0 on the first call, the condition
offset != outputPos is true and causes the output stream to be closed and
then re-created every time this method is called. In my testing, this
method is called repeatedly with 16K bytes of data until the file upload
has completed.

My implementation of file.createOutputStream(offset) is such that I only
want to call it once when the resume upload begins. I cannot have this
method called repeatedly.

I propose that if I were to insert one line between 268 and 269 this would
be resolved:
268.5 --> outputPos = offset;

So after the output stream is created on line 268, initialize outputPos to
be equal to offset. Then, the condition on line 263 will be false on the
second call to write (and all subsequent calls) and the data can be
uploaded 16K bytes at a time without needing to re-create the output stream.

Does this seem valid? Would it be applicable to everyone or only to me due
to my implementation of createOutputStream(offset) ?


262  public void write(byte[] data, long offset) throws IOException {
263             if (output != null && offset != outputPos) {
264                 IoUtils.closeQuietly(output);
265                 output = null;
266             }
267             if (output == null) {
268                 output = file.createOutputStream(offset);
269             }
270             output.write(data);
271             outputPos += data.length;
272         }

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message