Я работаю с WinSCP в PowerShell, чтобы вывести список файлов из подкаталогов подстановочных знаков. Однако $remotepath
не работал, если я поместил шаблон / маску между подкаталогами.
Это то, что у меня до сих пор:
param (
##not working with mask, need to put full path
$remotePath = "/ftpdata/*/infile/$currmon/",
$wildcard = "*$yesterday.*"
)
try
{ Add-Type -Path "WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "Hostnamme" UserName = "UserName" Password = "Password"
SshHostKeyFingerprint = "ssh-rsa 2048 ............................"
}
$session = New-Object WinSCP.Session
try
{ $session.Open($sessionOptions)
$files = $session.EnumerateRemoteFiles(
$remotePath, $wildcard, [WinSCP.EnumerationOptions]::None )
if ($files.Count -gt 0)
{
foreach ($fileInfo in $files)
{
Write-Host ("$($fileInfo.Name) with size $($fileInfo.Length), " +
"last modification at $($fileInfo.LastWriteTime)")
}
}
else
{
Write-Host "No files matching $wildcard found"
}
}
finally
{
$session.Dispose()
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}