This project is read-only.

Problem with sftp uploading

Mar 22, 2013 at 3:21 PM
Edited Mar 22, 2013 at 3:24 PM
I have problem with uploading of several big files in one session into linux server.

for example:
I try to upload 17 files in loop.

3 - success, after that I waiting during 1 hour and then i get exception:


System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle
waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1
uploadCallback)

I think that there is problem is in this part of code.

do
        {
            //  Cancel upload
            if (asyncResult != null && asyncResult.IsUploadCanceled)
                break;

            if (bytesRead > 0)
            {
                if (bytesRead < this.BufferSize)
                {
                    //  Replace buffer for last chunk of data
                    var data = new byte[bytesRead];
                    Buffer.BlockCopy(buffer, 0, data, 0, bytesRead);
                    buffer = data;
                }

                var writtenBytes = offset + (ulong)buffer.Length;
                this._sftpSession.RequestWrite(handle, offset, buffer, null, (s) =>
                {
                    if (s.StatusCode == StatusCodes.Ok)
                    {
                        expectedResponses--;
                        responseReceivedWaitHandle.Set();

                        //  Call callback to report number of bytes written
                        if (uploadCallback != null)
                        {
                            //  Execute callback on different thread                
                            this.ExecuteThread(() => { uploadCallback(writtenBytes); });
                        }
                    }
                });
                expectedResponses++;

                offset += (uint)bytesRead;

                bytesRead = input.Read(buffer, 0, buffer.Length);
            }
            else if (expectedResponses > 0)
            {
                //  Wait for expectedResponses to change
                this._sftpSession.WaitHandle(responseReceivedWaitHandle, this.OperationTimeout);
            }
        } while (expectedResponses > 0 || bytesRead > 0);

        this._sftpSession.RequestClose(handle);
    }


I think the variable bytesRead became = 0 but expectedResponses can't be 0...
Mar 23, 2013 at 1:15 PM
HI,

There might be be a problem which I investigating now but it will take me some time since I busy with my work related project now :(
I also have somebody submitting to me similar test case with examples, where he missing files.

I do however suspect that problem is in "while (expectedResponses > 0 || bytesRead > 0)" since I actually had a problem there before where I was checking only for expectedResponses case.

Basically what this lines says is to wait until all packets are sent and all bytes are read from the source stream.

I guess I will need to run some tests on huge files then too.
Can you specify how many file you sending and how big they are?
Also can you submit it as bug report so I dont forget to get back to it?

Thanks,
Oleg
Mar 23, 2013 at 2:43 PM
Edited Mar 23, 2013 at 3:00 PM
17 files on 2 gb
I add issue 1539
Mar 23, 2013 at 3:22 PM
Ok,
Thanks,
Oleg