You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Michael Benovich <mi...@hostedftp.com> on 2014/06/14 02:49:49 UTC
Trouble with SFTP resume upload
Hi,
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) ?
Thanks,
Mike
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 }
--
Mike
Hosted~FTP~
FTP in the Cloud
www.hostedftp.com
1-855-888-4FTP (4387)
Re: Trouble with SFTP resume upload
Posted by Guillaume Nodet <gn...@apache.org>.
Good catch !
Could you please raise a JIRA for this issue ? I think your proposal is
correct.
2014-06-14 2:49 GMT+02:00 Michael Benovich <mi...@hostedftp.com>:
> Hi,
>
> 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) ?
>
>
> Thanks,
> Mike
>
>
> 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 }
>
>
> --
> Mike
>
> Hosted~FTP~
> FTP in the Cloud
> www.hostedftp.com
> 1-855-888-4FTP (4387)
>