NET FTP Library
DownloadFilesInParallelAsync Method
Example 






KellermanSoftware.NetFtpLibrary Namespace > FTP Class : DownloadFilesInParallelAsync Method
The key of the dictionary is the local file path and the value is the ftp file path
Download files in Parallel as an Async Task using two threads with two FTP connections
Syntax
'Declaration
 
<System.Runtime.CompilerServices.AsyncStateMachineAttribute(KellermanSoftware.NetFtpLibrary.FTP/d__244)>
<System.Diagnostics.DebuggerStepThroughAttribute()>
Public Function DownloadFilesInParallelAsync( _
   ByVal files As System.Collections.Generic.Dictionary(Of String,String) _
) As System.Threading.Tasks.Task
'Usage
 
Dim instance As FTP
Dim files As System.Collections.Generic.Dictionary(Of String,String)
Dim value As System.Threading.Tasks.Task
 
value = instance.DownloadFilesInParallelAsync(files)
[System.Runtime.CompilerServices.AsyncStateMachine(KellermanSoftware.NetFtpLibrary.FTP/d__244)]
[System.Diagnostics.DebuggerStepThrough()]
public System.Threading.Tasks.Task DownloadFilesInParallelAsync( 
   System.Collections.Generic.Dictionary<string,string> files
)
public function DownloadFilesInParallelAsync( 
    files: System.Collections.Generic.Dictionary
): System.Threading.Tasks.Task; 
System.Runtime.CompilerServices.AsyncStateMachineAttribute(KellermanSoftware.NetFtpLibrary.FTP/d__244)
System.Diagnostics.DebuggerStepThroughAttribute()
public function DownloadFilesInParallelAsync( 
   files : System.Collections.Generic.Dictionary
) : System.Threading.Tasks.Task;
[System.Runtime.CompilerServices.AsyncStateMachine(KellermanSoftware.NetFtpLibrary.FTP/d__244)]
[System.Diagnostics.DebuggerStepThrough()]
public: System.Threading.Tasks.Task* DownloadFilesInParallelAsync( 
   System.Collections.Generic.Dictionary<string*,string*>* files
) 
[System.Runtime.CompilerServices.AsyncStateMachine(KellermanSoftware.NetFtpLibrary.FTP/d__244)]
[System.Diagnostics.DebuggerStepThrough()]
public:
System.Threading.Tasks.Task^ DownloadFilesInParallelAsync( 
   System.Collections.Generic.Dictionary<String^,String^>^ files
) 

Parameters

files
The key of the dictionary is the local file path and the value is the ftp file path
Example
//Create some test files
Dictionary<string, string> files = new Dictionary<string, string>();
 
for (int i = 0; i < 10; i++)
{
    string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "uploadfile" + i + ".txt");
    File.WriteAllText(filePath, "This is a test");
    files.Add(filePath, Path.GetFileName(filePath));
}
 
FTP ftp = new FTP(); //Trial Mode            
//FTP ftp = new FTP("place user name here", "place license key here");
 
// set the name of the FTP server( its URL )
ftp.HostAddress = "ftp.fsz.bme.hu"; // a hungarian university. change this to your ftp server
ftp.UserName = "anonymus"; // replace with your user name
ftp.Password = "user@mail.com"; // replace with your password
 
ftp.Connect();
 
ftp.CurrentDirectory = "/";
 
await ftp.UploadFilesInParallelAsync(files);
 
//Delete local files
foreach (var file in files)
{
    File.Delete(file.Key);
}
 
await ftp.DownloadFilesInParallelAsync(files);
 
ftp.Disconnect();
'Create some test files
Dim files As New Dictionary(Of String, String)()
 
For i As Integer = 0 To 9
    Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "uploadfile" & i & ".txt")
    File.WriteAllText(filePath, "This is a test")
    files.Add(filePath, Path.GetFileName(filePath))
Next i
 
Dim ftp As New FTP() 'Trial Mode
'FTP ftp = new FTP("place user name here", "place license key here");
 
' set the name of the FTP server( its URL )
ftp.HostAddress = "ftp.fsz.bme.hu" ' a hungarian university. change this to your ftp server
ftp.UserName = "anonymus" ' replace with your user name
ftp.Password = "user@mail.com" ' replace with your password
 
ftp.Connect()
 
ftp.CurrentDirectory = "/"
 
await ftp.UploadFilesInParallelAsync(files)
 
'Delete local files
For Each file In files
    System.IO.File.Delete(file.Key)
Next file
 
await ftp.DownloadFilesInParallelAsync(files)
 
ftp.Disconnect()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

FTP Class
FTP Members