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

Author Message
JACINTKA

Guest


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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
The Session.MoveFile does not support wildcards.

The bug, when using a wildcard-like filename is tracked here:
https://winscp.net/tracker/show_bug.cgi?id=1412
Guest




prikryl 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. Smile

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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License