How can i get a Filelist like Get-Childitem

Advertisement

shannra666
Joined:
Posts:
1

How can i get a Filelist like Get-Childitem

Hello,

we using Winscp .Net assembly to download Files from Ftp to a local Folder. Now sometimes it interrupt without any error. So my Files are not completed. So i will ad in my Windows Task a New Script. This Script should compare the Ftp-Folder with my local Folder. If not all Files from FTP in my local Folder, then win SCP should start sync again.

But i try the following without success, because the File List Remote cant be compare with the file List which i get with Get-Childitem from local Folder.

$rz_log = "C:\src\logs\RZ\RZ_log_Log_"+(get-date -format "yy-MM-dd")+".txt"
try
{
    # Load WinSCP .NET assembly
    # Use "winscp.dll" for the releases before the latest beta version.
    [Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\WinSCP\WinSCP.dll") | Out-Null
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::ftp
    $sessionOptions.HostName = "FTP-Server"
    $sessionOptions.UserName = "FTP-User"
    $sessionOptions.Password = "FTP-Pass"
 
    $session = New-Object WinSCP.Session
 

    try
    {
        # Connect
        $session.Open($sessionOptions)
        $directory = $session.ListDirectory("/clara-17")
        Compare-Object -ReferenceObject  $(Get-ChildItem 'FolderLocal' -Recurse) -DifferenceObject  $directory  -Property Name
                foreach ($fileInfo in $directory.Files)
        {
          Write-Host ("{0}" -f
                $fileInfo.Name)
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    #exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}

Can anybody give me an hint, how i can compare this two Folders?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum