Topic "report progress"

Author Message
[View user's profile]

Joined: 2012-05-07
Posts: 3
Is there anyway to report progress to a background worker with session.GetFiles?

Thank you.
[View user's profile]

Joined: 2012-05-07
Posts: 3
Sorry I didnt enter any code, but I didnt have any to enter using winscp, read through docs and google but couldnt find a way. I'd like to use winscp to report progress like shown below:
FileStream stream = File.OpenRead(filePath);
                byte[] buffer = new byte[2048];
                int contentLen = stream.Read(buffer, 0, buffer.Length);
                int totalReadBytesCount = contentLen;

                Stream reqStream = request.GetRequestStream();
                while (contentLen != 0)
                    reqStream.Write(buffer, 0, buffer.Length);
                    contentLen = stream.Read(buffer, 0, buffer.Length);
                    totalReadBytesCount += contentLen;
                    var progress = totalReadBytesCount * 100.0 / stream.Length;
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24736
Location: Prague, Czechia
Thanks for your post.

This request is being tracked already:
Martin Prikryl
[View user's profile]

Joined: 2012-05-07
Posts: 3
Ok cool, thank you, I got around the limitation by doing this:
 public static string FtpFilesSecurely(string file, string host, string direction, BackgroundWorker bw)
                            var fileInfo = session.GetFileInfo(file);
                            worker1.DoWork += (sender, e) =>
                                e.Result = worker1_DoWork(fileInfo, FTP, bw, file);

                            //Download files
                            TransferOperationResult transferResult =
                                session.GetFiles(file, FTP.sourceDirectory, false, transferOptions);

                            // Throw on any error

                            // Print results
                            return transferResult.IsSuccess ? "Download Succeeded." : "Download Failed.";
public static object worker1_DoWork(RemoteFileInfo fileInfo, CompanyFtpInfo FTP, BackgroundWorker bw, string file)
            const string filePart = ".filepart";
            file = FTP.sourceDirectory + file + filePart;
            while (!File.Exists(file))
            CalculateDownload(fileInfo, bw, file);
            return "Calculation Complete.";
private static void CalculateDownload(RemoteFileInfo fileInfo, BackgroundWorker bw, string file)
            long remoteFileSize = fileInfo.Length;
            var localFile = new FileInfo(file);
                long localFileSize = localFile.Length;
                while (localFileSize < remoteFileSize)
                    long progress = localFileSize*100/remoteFileSize;
                    bw.ReportProgress((int) progress);

                    localFile = new FileInfo(file);
                    localFileSize = localFile.Length;
                    //this works because as a file is downloaded it is called filename.ext.filepart
                    //when the file is done downloading it is then called filename.ext so therefore
                    //the original name doesnt exist anymore.
                    if (!File.Exists(file))

It doesn't work 100% but works pretty good, an advanced programmer could probably make it work better.
[View user's profile]

Joined: 2012-03-15
Posts: 5
Location: Russia

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License