Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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.
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
martin

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

The Session.MoveFile does not support wildcards.

The bug, when using a wildcard-like filename is tracked here:
https://winscp.net/tracker/1412
JACINTKA

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