How to upload a list of selected files in a listview

0 votes
asked Feb 21, 2017 by Lukas Matyska (43,890 points)

This question was converted from this comment of another question.

I am trying to use your software that I intend to buy... Currently I am trying to upload a list of selected files as in your example "FtpWinFormClient_CS" :
"await _ftp.UploadAsync(path, ".", TraversalMode.Recursive, TransferMethod.Copy, ActionOnExistingFiles.ThrowException);" ,
But this method takes only file by file.

Here is my code :

List<String> FilesList = new List<String>();
if (listLocal.SelectedItems.Count > 0)
    foreach (ListViewItem item in listLocal.SelectedItems)
        string path = Path.Combine(_localPath, item.Text);
string combindedString = string.Join(",", FilesList);
await _ftp.UploadAsync(combindedString, ".", TraversalMode.Recursive, TransferMethod.Copy, ActionOnExistingFiles.ThrowException);

So the question is how to upload a list of selected files in a listview

In advance, thank you for your answer !

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Feb 21, 2017 by Lukas Matyska (43,890 points)

The ftp.UploadAsync method can take two kind of parameters:

  1. A string which represents path to a file or a directory.
  2. The FileSet object, which can be used to define multiple files and directories.

If you want to simply upload single file or directory asynchronously, call the Upload method like this:

// localPath is path to single file or directory
await _ftp.UploadAsync(localPath, ".", TraversalMode.Recursive, TransferMethod.Copy, ActionOnExistingFiles.ThrowException);

If you want to upload multiple files and/or directories from one specific directory (I think this is your case), you can do it like this:

if (listLocal.SelectedItems.Count > 0)
    // initialize FileSet with current directory
    FileSet set = new FileSet(_localPath);
    foreach (ListViewItem item in listLocal.SelectedItems)
        // include selected items to FileSet
        if (item.Text != "." && item.Text != "..")
    // upload specified FileSet
    await _ftp.UploadAsync(set, ".", TransferMethod.Copy, ActionOnExistingFiles.ThrowException);
commented Feb 21, 2017 by netsub (120 points)
Wonderful it works like a wonder... I admit that I had a little trouble with the FileSet... But it is a very intelligent method...
Thanks also for the super fast response...