Differences

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

script_local_move_after_successful_upload 2016-02-04 script_local_move_after_successful_upload 2023-06-05 (current)
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 41: Line 41:
            if ($transfer.Error -eq $Null)             if ($transfer.Error -eq $Null)
            {             {
-                Write-Host ("Upload of {0} succeeded, moving to backup" -f +                Write-Host "Upload of $($transfer.FileName) succeeded, moving to backup"
-                    $transfer.FileName)+
                # Upload succeeded, move source file to backup                 # Upload succeeded, move source file to backup
                Move-Item $transfer.FileName $backupPath                 Move-Item $transfer.FileName $backupPath
Line 48: Line 47:
            else             else
            {             {
-                Write-Host ("Upload of {0} failed: {1}" -+                Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
- ···················$transfer.FileName, $transfer.Error.Message)+
            }             }
        }         }
Line 61: Line 59:
    exit 0     exit 0
} }
-catch [Exception]+catch
{ {
-    Write-Host $_.Exception.Message+    Write-Host "Error: $($_.Exception.Message)"
    exit 1     exit 1
} }
Line 88: Line 86:
echo Upload succeeded, moving local files echo Upload succeeded, moving local files
move *.* c:\backup\ move *.* c:\backup\
-exit 0+exit /b 0
:error :error
echo Upload failed, keeping local files echo Upload failed, keeping local files
-exit 1+exit /b 1
</code> </code>
 +
 +Contrary to the PowerShell script above, this solution is not transactionally safe. If new files appear in the local folder between times the upload starts and the archiving/moving starts, the new files will not get uploaded. For this reason, prefer using the PowerShell script.
 +
 +Another option is to move the files to an intermediate/temporary folder first, upload from there, and then move them to the backup location.
===== Further Reading ===== ===== Further Reading =====

Last modified: by martin