我想显示我的ProgressBar
上传过程的进度,这里是我的按钮的代码“上传”:
private void button2_Click(object sender, EventArgs e)
{
int Port = int.Parse(textBox2.Text);
string Host = textBox1.Text;
string Username = textBox3.Text;
string Password = textBox4.Text;
string WorkingDirectory = textBox6.Text;
string UploadDirectory = textBox5.Text;
FileInfo FI = new FileInfo(UploadDirectory);
string UploadFile = FI.FullName;
Console.WriteLine(FI.Name);
Console.WriteLine("UploadFile" + UploadFile);
var Client = new SftpClient(Host, Port, Username, Password);
Client.Connect();
if (Client.IsConnected)
{
var FS = new FileStream(UploadFile, FileMode.Open);
if (FS != null)
{
Client.UploadFile(FS, WorkingDirectory + FI.Name, null);
Client.Disconnect();
Client.Dispose();
MessageBox.Show(
"Upload complete", "Information", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
1条答案
按热度按时间zqry0prt1#
您必须为
SftpClient.UploadFile
的uploadCallback
参数提供回调。当然,您必须在后台线程上上传或使用异步上传(
SftpClient.BeginUploadFile
)。使用后台线程(任务)的示例:
Displaying progress of file download in a ProgressBar with SSH.NET