Skip to content

UploadedBytes wrong value #329

Closed
@creatorness

Description

@creatorness

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
                        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions