+1 vote

I am going to buy your product and I need to know if there is a way to show the uploading file status.

thanks and regards.

by
retagged by

1 Answer

0 votes
 
Best answer

You can find the Ftp.Progress event (and Ftp.BatchProgress) on the Ftp object.

Remember that when it is invoked from a different thread you need to
use BeginInvoke to update progress:

public class MainForm : Form
{
    private readonly Button _btnUpload;
    private readonly ProgressBar _progressBar;
    private readonly ListBox _listBox;

    public MainForm()
    {
        _btnUpload = new Button();
        _btnUpload.Text = "Upload";
        _btnUpload.Click += btnUpload_Click;
        _progressBar = new ProgressBar();
        _listBox = new ListBox();
        _btnUpload.Dock = DockStyle.Bottom;
        _listBox.Dock = DockStyle.Fill;
        _progressBar.Dock = DockStyle.Top;
        this.Controls.Add(_listBox);
        this.Controls.Add(_progressBar);
        this.Controls.Add(_btnUpload);
    }

    private void Ftp_Progress(object sender, ProgressEventArgs e)
    {
        this.BeginInvoke((MethodInvoker)(() =>
        {
            _progressBar.Value = (int)e.Percentage;
        }));
    }

    private void btnUpload_Click(object sender, EventArgs e)
    {
        Thread thread = new Thread(() =>
        {
            try
            {
                using (Ftp ftp = new Ftp())
                {
                    ftp.Progress += Ftp_Progress;
                    ftp.Connect("localhost");
                    Log("Connected. Logging in...");
                    ftp.Login("ftptest", "cypher");
                    foreach (string fileName in Directory.GetFiles("."))
                    {
                        ftp.Upload(Path.GetFileName(fileName), fileName);
                    }
                    ftp.Close();
                }
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        });
        thread.Start();
    }

    private void Log(string entry)
    {
        this.BeginInvoke((MethodInvoker)(() => _listBox.Items.Add(entry)));
    }

    [STAThread]
    private static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());


    }
};
by (297k points)
Progress problem when upload interrupts
...