Moving local files to different location with timestamp after successful upload

Skumar_CCSA used Ask the Experts™
Hi ,

I found this script it is useful saving my time.
i want help from experts...
after successful transfer it moving the file to archive..but every week the activity will go and chances for overwrite.
I want to have the dateandtime stamp to put while moving the files to archive..
can help to modify the code pls..

Localpathfile : E:\ABC\Zip_Source\
backupPath = "E:\ABC\Backup\

Script from internet

# Upload Files to FTP and move source files to archive
param (
    $localPath = "E:\ABC\Zip_Source\*.p7",
    $remotePath = "/home/user/",
    $backupPath = "E:\ABC\Backup\"
    # Load WinSCP .NET assembly
    Add-Type -Path "WinSCPnet.dll"
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = ""
        UserName = "user"
        Password = "mypassword"
        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
    $session = New-Object WinSCP.Session
        # Connect
        # Upload files, collect results
        $transferResult = $session.PutFiles($localPath, $remotePath)
        # Iterate over every transfer
        foreach ($transfer in $transferResult.Transfers)
            # Success or error?
            if ($transfer.Error -eq $Null)
                Write-Host "Upload of $($transfer.FileName) succeeded, moving to backup"
                # Upload succeeded, move source file to backup
                Move-Item $transfer.FileName $backupPath
                Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

If you have many files to move tar or rsync both preserve all file ownership + permissions + timestamps.


This is for upload files to ftp..
want the timestamp to put moving file.


pls help....
Move-Item $transfer.FileName $backupPath
I want the moving file to have timestamp..
Either way fine
i got it and able to do myself.
Now i can see the file moved to archive after upload and moved file with datetime
             $fileWithOutExt = [io.path]::GetFileNameWithoutExtension($transfer.FileName)
                $MoveFile1 = "$backupPath\$($fileWithOutExt)_$date.p7"
                Move-Item $transfer.FileName $MoveFile1

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial