Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace AR_Tool
- {
- class ftpClient
- {
- Uri uri;
- ProgressBar progressbar;
- MyWebClient webclient;
- string url;
- string path;
- string username;
- string password;
- NetworkCredential netcredentials;
- public ftpClient(string url, string path, string username, string password, ProgressBar progressbar)
- {
- this.url = url;
- this.path = path;
- this.username = username;
- this.password = password;
- this.progressbar = progressbar;
- webclient = new MyWebClient();
- netcredentials = new NetworkCredential(username, password);
- webclient.Credentials = netcredentials;
- uri = new Uri(url);
- this.progressbar.Minimum = 0;
- this.progressbar.Maximum = 100;
- this.progressbar.Value = 0;
- }
- public async void DownloadFile()
- {
- try
- {
- webclient.DownloadProgressChanged += (s, t) =>
- {
- progressbar.Value = t.ProgressPercentage;
- };
- webclient.DownloadFileCompleted += (s, t) =>
- {
- progressbar.Visible = true;
- progressbar.Value = 0;
- };
- await webclient.DownloadFileTaskAsync(uri, path);
- }
- catch (Exception c)
- {
- MessageBox.Show("Connessione ad internet non disponibile, riprovare");
- }
- }
- internal class MyWebClient : WebClient
- {
- protected override WebRequest GetWebRequest(Uri address)
- {
- FtpWebRequest req = (FtpWebRequest)base.GetWebRequest(address);
- req.UsePassive = false;
- return req;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement