Add-Type -Path "WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = "ftp://ftp.example.com/"
UserName = "username"
Password = "password"
FtpSecure = [WinSCP.FtpSecure]::Explicit
TlsHostCertificateFingerprint = "a6:c3:e8:ce:22:c3:39:27:0d:00:ac:63:cf:78:6d:45:fd:c0:29:b0"
}
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
$source = '/incoming'
$dest = '/incoming/History'
$files = $session.EnumerateRemoteFiles(
$source, $Null, [WinSCP.EnumerationOptions]::MatchDirectories)
foreach ($file in $files)
{
$session.Open($sessionOptions)
Write-Host "Renaming $file..."
$session.MoveFile($file.FullName, [WinSCP.RemotePath]::CombinePaths($dest, $file.Name))
}
finally
{
$session.Dispose()
}
Ошибка ниже:
"Connection failed.
Connection failed."
At line:17 char:1
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
Exception calling "EnumerateRemoteFiles" with "3" argument(s): "Session is not
opened"
At line:22 char:1
+ $files = $session.EnumerateRemoteFiles(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
Exception calling "Open" with "1" argument(s): "Connection failed.
Connection failed."
At line:27 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
Я хочу переместить удаленные файлы из папки FTP в подкаталог на том же FTP, используя переименование в WinSCP. Все остальные процессы, которые я использовал для этого сервера, хорошо работали с WebClientRequest, но по какой-то причине у меня возникли проблемы с использованием модуля WinSCP.