문제

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

?

도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top