NET SFTP Library
UploadFilesInParallelAsync Method
Example 






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

Parameters

files
The key of the dictionary is the local file path and the value is the sftp file path
Example
//Create some test files to upload
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));
}
 
Stopwatch watch = new Stopwatch();
 
SFTP sftp = new SFTP(); //Trial Mode            
//SFTP sftp = new SFTP("place user name here", "place license key here");
 
// set the name of the SFTP server( its URL )
sftp.HostAddress = "sftp.fsz.bme.hu"; // a hungarian university. change this to your sftp server
sftp.UserName = "anonymus"; // replace with your user name
sftp.Password = "user@mail.com"; // replace with your password
 
sftp.EnableLogging();
sftp.Connect();
 
sftp.CurrentDirectory = "/TestDir";
 
await sftp.UploadFilesInParallelAsync(files);
        
sftp.Disconnect();
'Create some test files to upload
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 watch As New Stopwatch()
 
Dim sftp As New SFTP() 'Trial Mode
'SFTP sftp = new SFTP("place user name here", "place license key here");
 
' set the name of the SFTP server( its URL )
sftp.HostAddress = "sftp.fsz.bme.hu" ' a hungarian university. change this to your sftp server
sftp.UserName = "anonymus" ' replace with your user name
sftp.Password = "user@mail.com" ' replace with your password
 
sftp.EnableLogging()
sftp.Connect()
 
sftp.CurrentDirectory = "/TestDir"
 
await sftp.UploadFilesInParallelAsync(files)
 
sftp.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

SFTP Class
SFTP Members