Differences
This shows you the differences between the selected revisions of the page.
script_locking_files_while_uploading 2017-01-11 | script_locking_files_while_uploading 2022-06-16 (current) | ||
Line 5: | Line 5: | ||
Common workarounds are: | Common workarounds are: | ||
- | - Upload "done" file once an upload of data files finishes and have the automated system wait for the "done" file before processing the data files. This is easy solution, but won't work in multi-user environment. | + | - Upload "done" file once an upload of data files finishes and [[script_downloading_when_done_file_exists|have the automated system wait for the "done" file before processing the data files]]. This is easy solution, but won't work in multi-user environment. |
- Upload data files to temporary ("upload") folder and move them atomically to target folder once the upload finishes. | - Upload data files to temporary ("upload") folder and move them atomically to target folder once the upload finishes. | ||
- Upload data files to distinct temporary name, e.g. with ''.filepart'' extension, and rename them atomically once the upload finishes. Have the automated system ignore the ''.filepart'' files. | - Upload data files to distinct temporary name, e.g. with ''.filepart'' extension, and rename them atomically once the upload finishes. Have the automated system ignore the ''.filepart'' files. | ||
+ | - A gross hack is to periodically check for file attributes (size and time) and consider the upload finished, if the attributes has not changed for some time interval. | ||
Here we focus on the third approach (although the second is very similar, implementation-wise). | Here we focus on the third approach (although the second is very similar, implementation-wise). | ||
- | ===== Using Transfer to temporary filename feature ===== | + | ===== [[temporary_filename]] Using Transfer to temporary filename feature ===== |
With [[sftp|SFTP protocol]], you can use [[resume#automatic|Transfer to temporary filename]] feature to have WinSCP handle the rename automatically for you. | With [[sftp|SFTP protocol]], you can use [[resume#automatic|Transfer to temporary filename]] feature to have WinSCP handle the rename automatically for you. | ||
Line 52: | Line 53: | ||
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 83: | Line 84: | ||
{ | { | ||
# Remove suffix | # Remove suffix | ||
- | $finalName = $transfer.Destination.SubString(0, $transfer.Destination.Length - $suffix.Length) | + | $finalName = |
- | Write-Host ("Renaming uploaded file {0} to final name {1}" -f $transfer.Destination, $finalName) | + | ···············$transfer.Destination.SubString( |
+ | ····················0, $transfer.Destination.Length - $suffix.Length) | ||
+ | Write-Host "Renaming uploaded file $($transfer.Destination) to $finalName" | ||
# Rename uploaded file to its final name | # Rename uploaded file to its final name | ||
$session.MoveFile($transfer.Destination, $finalName) | $session.MoveFile($transfer.Destination, $finalName) | ||
Line 97: | Line 100: | ||
exit 0 | exit 0 | ||
} | } | ||
- | catch [Exception] | + | catch |
{ | { | ||
- | Write-Host ("Error: {0}" -f $_.Exception.Message) | + | Write-Host "Error: $($_.Exception.Message)" |
exit 1 | exit 1 | ||
} | } |