Differences

This shows you the differences between the selected revisions of the page.

library_example_delete_after_successful_download 2017-10-03 library_example_delete_after_successful_download 2022-06-16 (current)
Line 1: Line 1:
====== Deleting remote files after successful remote to local synchronization ====== ====== Deleting remote files after successful remote to local synchronization ======
-//For background, see article [[faq_delete_synchronized_files|How do I create script that synchronizes files and deletes synchronized files from source afterward?]]//+//For background, see article [[faq_delete_synchronized_files|*]]//
The following example uses [[library|WinSCP .NET assembly]] from a [[library_powershell|PowerShell]] script. If you have another preferred language, you can easily translate it. The following example uses [[library|WinSCP .NET assembly]] from a [[library_powershell|PowerShell]] script. If you have another preferred language, you can easily translate it.
Line 22: Line 22:
        UserName = "user"         UserName = "user"
        Password = "mypassword"         Password = "mypassword"
-        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+        SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
    }     }
Line 51: Line 51:
                Write-Host "Download of $($download.FileName) succeeded, removing from source"                 Write-Host "Download of $($download.FileName) succeeded, removing from source"
                # Download succeeded, remove file from source                 # Download succeeded, remove file from source
-                $removalResult = +                $filename = [WinSCP.RemotePath]::EscapeFileMask($download.FileName) 
- ···················$session.RemoveFiles($session.EscapeFileMask($download.FileName))+                $removalResult = $session.RemoveFiles($filename)
                if ($removalResult.IsSuccess)                 if ($removalResult.IsSuccess)
Line 65: Line 65:
            else             else
            {             {
-                Write-Host "Download of $($download.FileName) failed: $($download.Error.Message)"+                Write-Host
 +····················"Download of $($download.FileName) failed: $($download.Error.Message)")
            }             }
        }         }
Line 77: Line 78:
    exit 0     exit 0
} }
-catch [Exception]+catch
{ {
    Write-Host "Error: $($_.Exception.Message)"     Write-Host "Error: $($_.Exception.Message)"

Last modified: by martin