WinSCP .NET library - rename command vs.non-matched wildcard on remote end results in error

Advertisement

JACINTKA
Guest

WinSCP .NET library - rename command vs.non-matched wildcard on remote end results in error

Hi,

If you use the library and issue a wildcard rename like this (this is a PowerShell excerpt):

$filestotransfer = ($dirpair.source + "/" + $dirpair.mask)
$destmask = $dirpair.mask + $mysuffix
$sess.MoveFile($filestotransfer, $destmask)

If the mask for the source does not have any matches, you have an error like this:

Element "mv" not found in the log file

Guess the case when the wildcard does not match is not handled properly. It can be worked around by fetching a filelist and checking with a regex if any of the files will match, and only run the command if there is something for ti to actually do, but it is a pain in the back IMHO, and a workaround anyway. Could someone please do something about that?

thanks, regards,
--
J

Reply with quote

Advertisement

Guest

Re: WinSCP .NET library - rename command vs.non-matched wildcard on remote end results in error

martin wrote:

The Session.MoveFile does not support wildcards.

Thanks for the answer, but... "does not support" - does this mean it is not meant to, and the functionality is a "lucky coincidence"; or that what I see is a "should not happen" type of thing? Only asking because it does seem to work fine none the less, apart from the small thing I mentioned. :-)

Anyways, just in case someone hits this, here is a workaround (ugly as all hell, but gets the job done):
$filestotransfer = ($dirpair.source + "/" + $dirpair.mask)
$destmask = $dirpair.mask + $mysuffix

#workaround to wildcard not matched in Movefile
if (($sess.ListDirectory($dirpair.source).Files | where { $_.Name -match ((([string]$dirpair.mask).Replace(".","\.").Replace("*",".*")) + "$") }).Count -ge 1) {
$sess.MoveFile($filestotransfer, $destmask) |Out-Null
}

Regards,
--
Jacint

Reply with quote

martin
Site Admin
martin avatar

Re: WinSCP .NET library - rename command vs.non-matched wildcard on remote end results in error

The MoveFile was never meant to support wildcards. But in fact it was implemented in a way that it actually does. It's not recommended to use it like that, as the behavior may break in future versions.

Reply with quote

Advertisement

You can post new topics in this forum