0 votes
by (140 points)

The multiple file upload PutFiles have overwrite or rename option, Does PutFile single file have similar options? If the file is already on the remote folder, does putFile overwrite the remote file?

Why there is no function similar to Upload but providing a list of file names instead of a whole folder? This seems quite odd that the Upload either takes a set of files (*.ext) or whole folder but not a list of filenames,

Applies to: Rebex SFTP

1 Answer

0 votes
by (58.9k points)
edited by

Yes, the Sftp.PutFile method overrides the remote file if it already exists at the server and there is currently no option to change this behaviour in Rebex SFTP. With the advanced Sftp.Upload method you can specify what action will take place in case the file already exists so this is the way to go even for a single file upload.

Actually, the Sftp.Upload method can also be instructed to specify a list of file names via the FileSet class. Please try the code below to specify the files one by one and upload them to the server with just one method call:

// specify a list of files to upload from the "C:\temp" directory
FileSet localFiles = new FileSet(@"C:\temp");
localFiles.Include("file.pdf", TraversalMode.MatchFilesShallow);
localFiles.Include("file.txt", TraversalMode.MatchFilesShallow);
localFiles.Include("file2.txt", TraversalMode.MatchFilesShallow);

Sftp sftp = new Sftp();
sftp.Connect("server");
sftp.Login("username", "password");

// upload the local files specified by the FileSet instance
sftp.Upload(localFiles, "remoteDirectory");

sftp.Disconnect();
by (120 points)
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);
                        FilesList.Add(path);  
                    }
                string combindedString = string.Join(",", FilesList);
                //MessageBox.Show(combindedString);
                    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 !
by (72.7k points)
@netsub: your comment is not related to this thread. I created new question from your comment and I answered it. Please see http://forum.rebex.net/6824/how-to-upload-a-list-of-selected-files-in-a-listview
...