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