Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task DownloadMultipleFilesConcurrentFromFTP(int NumberOfConnections, string AppName, string RemoteUrl)
- {
- var downloadTasks = new List<Task>();
- for (int i = 0; i < NumberOfConnections; i++){
- downloadTasks.Add(DownloadFile(AppName, RemoteUrl));
- }
- await Task.WhenAll(downloadTasks);
- }
- public async Task DownloadFile(string AppName, string RemoteUrl)
- {
- var ftp = new FtpClient(FTPHost, networkCredential);
- ftp.ConnectTimeout = ConnectTimeout;
- ftp.SocketPollInterval = SocketPollInterval;
- ftp.ReadTimeout = ReadTimeout;
- ftp.DataConnectionConnectTimeout = DataConnectionConnectTimeout;
- ftp.DataConnectionReadTimeout = DataConnectionReadTimeout;
- await ftp.ConnectAsync();
- if (ftp.IsConnected)
- {
- using (FileStream read = new FileStream("settings.xml", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
- {
- if (ftp.IsConnected == true)
- {
- if (File.Exists("settings.xml"))
- {
- Information info = (Information)xs.Deserialize(read);
- if (Directory.Exists(info.Downloads))
- {
- await ftp.DownloadFileAsync(info.Downloads + "\\" + AppName, RemoteUrl, FtpLocalExists.Overwrite, FtpVerify.Retry);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment