Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: FTP Sync files to local folder

sameer12 wrote:

I want write 2 files.
1. log files errors or succeded.
2. session information

And what problem do you have with implementing this?
Just process the results returned in SynchronizationResult in any way you like:
https://winscp.net/eng/docs/library_synchronizationresult
martin

Re: FTP Sync files to local folder

I'm lost. Did you resolve the problem from your first post?
sameer12

FTP Sync files to local folder

Hello Experts
I am able to Synchronize files by changing the area # Synchronize files for local sync and remote sync only one part remaining.

I want write 2 files.
1. log files errors or succeded.
2. session information


       # Synchronize files

        $synchronizationResult = $session.SynchronizeDirectories(
      [WinSCP.SynchronizationMode]::Local, "d:\FTP\Caspio", "/", $True, $False, 1, $TransferOptions)



       # Synchronize files

        $synchronizationResult = $session.SynchronizeDirectories(
      [WinSCP.SynchronizationMode]::Remote, "d:\FTP\Caspio", "/", $True, $False, 1, $TransferOptions)
sameer12

FTP Sync files to local folder

Hello Experts!
I got the code from below link i think which works on SFTP . I am trying to work the code
sync ftp files to local directory . I have change the # Set up session options area and # Synchronize files area but finding an error

Error: Exception calling "Check" with "0" argument(s): "Error listing directory '/*.*'.
Could not retrieve directory listing
The filename, directory name, or volume label syntax is incorrect. "



https://winscp.net/eng/docs/library_session_synchronizedirectories



# Load WinSCP .NET assembly

Add-Type -Path "WinSCPnet.dll"
 
# Session.FileTransferred event handler
 
function FileTransferred
{
    param($e)
 
    if ($e.Error -eq $Null)
    {
        Write-Host "Upload of $($e.FileName) succeeded"
    }
    else
    {
        Write-Host "Upload of $($e.FileName) failed: $($e.Error)"
    }
 
    if ($e.Chmod -ne $Null)
    {
        if ($e.Chmod.Error -eq $Null)
        {
            Write-Host "Permissions of $($e.Chmod.FileName) set to $($e.Chmod.FilePermissions)"
        }
        else
        {
            Write-Host "Setting permissions of $($e.Chmod.FileName) failed: $($e.Chmod.Error)"
        }
 
    }
    else
    {
        Write-Host "Permissions of $($e.Destination) kept with their defaults"
    }
 
    if ($e.Touch -ne $Null)
    {
        if ($e.Touch.Error -eq $Null)
        {
            Write-Host "Timestamp of $($e.Touch.FileName) set to $($e.Touch.LastWriteTime)"
        }
        else
        {
            Write-Host "Setting timestamp of $($e.Touch.FileName) failed: $($e.Touch.Error)"
        }
 
    }
    else
    {
        # This should never happen during "local to remote" synchronization
        Write-Host "Timestamp of $($e.Destination) kept with its default (current time)"
    }
}
 
# Main script
 
try
{      
   # Set up session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Ftp
    HostName = "***********"
    PortNumber = 21
    UserName = "**********"
    Password = "*****"
    FtpSecure = [WinSCP.FtpSecure]::Explicit
    TlsHostCertificateFingerprint = "5f:66:34:ad:e9:a9:8f:c2:60:79:d8:38:f6:da:7a:0b:69:d8:94:3C"   
      
    }
 
    $session = New-Object WinSCP.Session
    try
    {
        # Will continuously report progress of synchronization
        $session.add_FileTransferred( { FileTransferred($_) } )
 
        # Connect
        $session.Open($sessionOptions)
 
        # Synchronize files
        $synchronizationResult = $session.SynchronizeDirectories(
            [WinSCP.SynchronizationMode]::Remote, "D:\FTP\", "/*.*", $False)
 
        # Throw on any error
        $synchronizationResult.Check()
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}