Single file upload by SFTP.PutFile question

0 votes
asked May 22, 2015 by joel (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
answered May 24, 2015 by Tomas Knopp (58,580 points)
edited May 26, 2015 by Tomas Knopp

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.Login("username", "password");

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

commented Feb 20 by netsub (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);
                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 !
commented Feb 21 by Lukas Matyska (38,400 points)
@netsub: your comment is not related to this thread. I created new question from your comment and I answered it. Please see