Reputation: 4547
I am trying to upload the contents of a folder (but not the sub-folders, which have backup files, archive files and errored files) to a server using the WinSCP .NET assembly. Is this even possible? If so, how do I do it?
Quick code clip of my existing piece:
// string mode ...
// Session sess ...
// TransferOperationResult res ...
TransferOptions tOpts = new TransferOptions();
tOpts.FileMask = c.SearchPattern;
tOpts.TransferMode = TransferMode.Binary;
tOpts.PreserveTimestamp = true;
SetMessage("Uploading files");
res = sess.PutFiles(Path.Combine(c.LocalPath, c.SearchPattern),
c.RemotePath,
c.DeleteAfterXFer,
tOpts);
Is there some way of saying something to the effect of:
tOpts.TopDirectoryOnly = true
?
Upvotes: 2
Views: 2305
Reputation: 202360
Use file mask |*/
to exclude all (sub-)directories.
Use the TransferOptions.FileMask
property to set the file mask.
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "|*/";
session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions).Check();
Specifically for your sample, do:
tOpts.FileMask = c.SearchPattern + "|*/";
Also documented in WinSCP FAQ How do I transfer (or synchronize) directory non-recursively?
Upvotes: 2