Differences
This shows you the differences between the selected revisions of the page.
faq_delete_synchronized_files 2019-03-22 | faq_delete_synchronized_files 2023-05-23 (current) | ||
Line 2: | Line 2: | ||
You have a source local (or remote) folder, where new files are being added by some external process. You want to make sure that these files gets regularly transferred to remote (or local) folder. And you want to remove the source local (or remote) files once they are safely transferred. | You have a source local (or remote) folder, where new files are being added by some external process. You want to make sure that these files gets regularly transferred to remote (or local) folder. And you want to remove the source local (or remote) files once they are safely transferred. | ||
- | First of all, such an operation should not be called [[task_synchronize|synchronization]], as it does not end with source and destination folders being synchronized. Anyway, leaving a terminology aside... | + | First of all, such an operation should not be called [[task_synchronize|synchronization]], as it does not end with source and destination folders being synchronized. Anyway, leaving terminology aside... |
===== [[moving]] Moving Files ===== | ===== [[moving]] Moving Files ===== | ||
- | Supposing you always want to upload all files from the source to the destination folder, you can simply move the files to the destination folder. | + | Supposing you always want to upload (or download) all files from the source to the destination folder, you can simply move the files to the destination folder. |
You can do this using ''-delete'' switch of the ''[[scriptcommand_put|put]]'' (or ''[[scriptcommand_get|get]]'') command. WinSCP deletes the source file, when it is successfully transferred to the destination folder only. | You can do this using ''-delete'' switch of the ''[[scriptcommand_put|put]]'' (or ''[[scriptcommand_get|get]]'') command. WinSCP deletes the source file, when it is successfully transferred to the destination folder only. | ||
Line 14: | Line 14: | ||
===== Synchronizing and Deleting Transferred Files ===== | ===== Synchronizing and Deleting Transferred Files ===== | ||
- | If it can happen that the same file is both in the source and the destination folder, and you do not want to upload such files, you can use synchronization and delete only transferred files afterward. | + | If it can happen that the same file is both in the source and the destination folder, and you do not want to upload (or download) such files, you can use synchronization and delete only transferred files afterward. |
A simple way to implement this is using both ''-delete'' and ''-neweronly'' switches of the ''[[scriptcommand_put|put]]'' (or ''[[scriptcommand_get|get]]'') command | A simple way to implement this is using both ''-delete'' and ''-neweronly'' switches of the ''[[scriptcommand_put|put]]'' (or ''[[scriptcommand_get|get]]'') command | ||
Line 24: | Line 24: | ||
---- | ---- | ||
- | If you need more control (like if you want to delete the files only after all of them are transferred successfully), you can implement this easily using [[library|WinSCP .NET assembly]]. See example [[library_example_delete_after_successful_download|Deleting remote files after successful remote to local synchronization]]. | + | If you need more control (like if you want to delete the files only after all of them are transferred successfully), you can implement this easily using [[library|WinSCP .NET assembly]]. See example [[library_example_delete_after_successful_download|*]]. |
If you do not want to use .NET assembly: Perform the synchronization using ''[[scriptcommand_synchronize|synchronize]]'' command. Make sure the script generates [[logging_xml|XML log file]]. You can then [[logging_xml#parse|parse]] the log file to enumerate files that got successfully transferred, and use the list, to generate script to delete the source copies. | If you do not want to use .NET assembly: Perform the synchronization using ''[[scriptcommand_synchronize|synchronize]]'' command. Make sure the script generates [[logging_xml|XML log file]]. You can then [[logging_xml#parse|parse]] the log file to enumerate files that got successfully transferred, and use the list, to generate script to delete the source copies. | ||
- | |||
~~NOTOC~~ | ~~NOTOC~~ | ||