Temp file - Last file not MOVED

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 7 months, 4 weeks ago.

  • Author
    Posts
  • #62815

    Ri
    Participant

    Hi,

    I have the following code and it copies all the files from "temp" to "incomingfiles" folder – Though the last file doesn't move to the incomingfiles folder and remains in the temp folder. Why does this happen?

    Any help please with the code or what is causing this;

    #Sub folder used to hold newly fetched encrypted zips
    $temporarySubfolder = "Temp\"
    #Sub folder used to hold decrypted uncompressed files
    $unzipSubdirFolder = "ZipTemp\"
    #Output folder for fetched, decrypted, re-compressed files
    $destinationSubfolder = "IncomingFiles\"

    # Destination directories
    $temporaryTransferFolder = Join-Path $rootFolder $temporarySubfolder
    $destinationFolder = Join-Path $rootFolder $destinationSubfolder

    # Set transfer options to simple binary transfer, overwriting existing file
    # This is because we are handling abort resume ourselves
    $transferOptions = New-Object WinSCP.TransferOptions -Property @{
    TransferMode = [WinSCP.TransferMode]::Binary
    ResumeSupport = New-Object WinSCP.TransferResumeSupport -Property @{
    State = [WinSCP.TransferResumeSupportState]::Off
    }
    OverwriteMode = [WinSCP.OverwriteMode]::Overwrite
    }

    foreach ($remoteFile in $collectionFiles) {
    Write-Host "Retrieving " $remoteFile.Name

    #Determine path to remot file
    $remoteFilePath = $remotePath + "/" + $remoteFile.Name
    $localTempFilePath = Join-Path $temporaryTransferFolder $remoteFile.Name

    #Fetch the file
    $session.GetFiles($session.EscapeFileMask($remoteFilePath), $localTempFilePath).Check()

    #Verify transfer with checksum
    $remoteChecksum = [System.BitConverter]::ToString($session.CalculateFileChecksum("sha-1", $remoteFilePath))
    $sha1 = [System.Security.Cryptography.SHA1]::Create()
    $localChecksum = "NotYetSetNotNull"
    try {
    $localStream = [System.IO.File]::OpenRead($localTempFilePath)
    $localChecksum = [System.BitConverter]::ToString($sha1.ComputeHash($localStream))
    }
    finally
    {
    $localStream.close()
    }

    Thanks...

  • #62845

    Don Jones
    Keymaster

    Would you mind posting your code with the code formatting, as indicated in the bullet list above the posting text box? It's unfortunately very difficult to follow without formatting.

You must be logged in to reply to this topic.