I am trying to set the WinSCP filemask so that any file in a local directory is uploaded to a remote directory on a file by file basis, without including the local directory name, itself, in the remote directory. The following works:
TransferOperationResult tR;
tR = session.PutFiles(_localPath + "*", _remotePath);
but I'd like to use a filemask instead of the + "*"
.
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.FileMask = "*";
TransferOperationResult tR;
tR = session.PutFiles(_localPath, _remotePath, false, transferOptions);
Is that possible? With either *
or *.*
filemask then the _localPath
uploads all files in the directory but includes the local directory name in the remote directory as well. I checked WinSCP filemask and TransferOptions but I didn't see an easy way...
Keep _localPath + "*"
and set TransferOptions.FileMask
on top of that.
Or even better, use RemotePath.Combine
.
TransferOptions transferOptions = new TransferOptions();
// a sample filemask, so that it makes a sense to set the FileMask
transferOptions.FileMask = "*>1H";
string sourcePath = RemotePath.Combine(_localPath, "*");
TransferOperationResult tR;
tR = session.PutFiles(sourcePath, _remotePath, false, transferOptions);
See a documentation of the localPath
parameter:
Full path to local file or directory to upload. Filename in the path can be replaced with Windows wildcard to select multiple files. To upload all files in a directory, use mask
*
.
So a value of the parameter must be /foo/bar/*
.
The TransferOptions.FileMask
is an additional filter on top of the wildcard in localPath
parameter.