Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UploadedBytes wrong value #329

Closed
creatorness opened this issue Oct 26, 2017 · 1 comment · Fixed by #1184
Closed

UploadedBytes wrong value #329

creatorness opened this issue Oct 26, 2017 · 1 comment · Fixed by #1184

Comments

@creatorness
Copy link

Hello,
I have a small problem and do not know if this is my mistake or a bug.
I use the SftpClient to upload a file. For this I use BeginUploadFile with Filestream.
In the end I check with uploadhandler.UploadedBytes if the file was uploaded correctly.
But there always comes a different result out and only occasionally the right number.
Here is the simplified code:

SftpClient client = new SftpClient(host, port, user, password);
client.Connect();
FileStream fileStream =  new FileStream(source, FileMode.Open);
SftpUploadAsyncResult uploadhandler = client.BeginUploadFile(fileStream, target, null, null) as SftpUploadAsyncResult;

                        while (!uploadhandler.IsCompleted)
                        {
                                Thread.Sleep(500);

                        }
                        client.EndUploadFile(uploadhandler);
                        FileInfo fi = new FileInfo(source);
                        if (uploadhandler.UploadedBytes == Convert.ToUInt64(fi.Length))
                        {
                            return true;
                        } else {
                            return false
                        }
@Kizmar
Copy link

Kizmar commented Mar 22, 2018

We also noticed the value returned in the UploadedBytes property wasn't reliable. I was hoping to use it to determine if an upload was successful, but we resorted to using Exists() instead.

Example:

client.BeginUploadFile(stream, path, true, result =>
{
    try
    {
        var exists = client.Exists(path);
        tcs.TrySetResult(exists);
    }
    catch (Exception e)
    {
        tcs.TrySetException(e);
    }
}, null);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants