DownloadAsync Method

0 votes
asked Apr 22, 2014 by emmanuelmorenot (210 points)
edited Apr 23, 2014

how to use the DownloadAsync Method (FileSet, String, TransferMethod, ActionOnExistingFiles, Object).

is necessary to use other methods as ConnectAsync and DisconnectAsync ?

there any example in the forum?

still can not find it ,grateful if you help me with an example


Applies to: Rebex SFTP, Rebex FTP/SSL

1 Answer

+2 votes
answered Apr 23, 2014 by Pavel Matyska (15,060 points)
edited Apr 23, 2014
Best answer


to use any file or directory operation on SFTP server, you need to be connected and logged to the server. You can use sftp.Connect or sftp.ConnectAsync method, then sftp.Login or sftp.LoginAsync method, which one you prefer.

Here is small sample code:

        // prepare local target directory
        string localDir = @"C:\temp\down";

        if (!Directory.Exists(localDir))

        // connect and login data
        string server = "";
        string username = "demo";
        string password = "password";

        // connect and login to sftp server
        // using 'using' statement allows automatic dispose of Sftp client
        using (Sftp client = new Sftp())
            client.Login(username, password);

            Task download = client.DownloadAsync(new FileSet("/", "**.txt"), localDir, TransferMethod.Copy, ActionOnExistingFiles.OverwriteOlder);

            // while the download is running do other job,
            // but make sure the download is complete 
            // before disconnecting and disposing the client
            // with .net 4.5 using 'await' key word is the best way to do this 
            while (!download.IsCompleted)

            // now we are complete and safe to disconnect
commented Apr 23, 2014 by emmanuelmorenot (210 points)
edited Apr 23, 2014

thank you very much, it was very helpful to me :)