Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: ssh.net uploading with progress bar

$
0
0
hi friends
how to use progress bar when uploading file ?
this is my code for uploading file to server

please help , thanks
private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
 
 
            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title = "Browse Text Files";
 
 
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;
 
 
            openFileDialog1.DefaultExt = "txt";
            openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
 
 
            openFileDialog1.ReadOnlyChecked = true;
            openFileDialog1.ShowReadOnly = true;
 
 
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtPath.Text = openFileDialog1.FileName;
            }
        }
 
 
        private void btnUpload_Click(object sender, EventArgs e)
        {
            using (Renci.SshNet.SftpClient sftp = new Renci.SshNet.SftpClient(txtHost.Text, txtUsername.Text, txtPassword.Text))
            {
                using (Stream fin = File.OpenRead(txtPath.Text))
                {
                    try
                    {
                        sftp.ConnectionInfo.Timeout = new TimeSpan(0, 0, 30);
 
 
                        sftp.Connect();
 
 
                        sftp.UploadFile(fin, "/upload/" + "salam.txt");
                        MessageBox.Show("Uploaded Succesfull");
                         
                    }
                    catch
                    {
                        MessageBox.Show("Uploading Error...");
                    }
                }
            }
        }

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>