TLS FTP Connection Will not open when recursing Files from FTP Directory To Subdirectory(History)

Advertisement

AGNL
Joined:
Posts:
2
Location:
USA

TLS FTP Connection Will not open when recursing Files from FTP Directory To Subdirectory(History)

It works fine when I grab the files, but when I created a new script to move them after download on the FTP server to a sub directory it refuses to open the connection. I opened the WinSCP app and pasted the credentials from their thinking it was an issue with my scripting given I used the same script for an SSH connection, but no dice. The connection will not open. Any Suggestions?[/code]

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()
}


Error below
"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

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum