I am trying to:
- Transfer a
zipfile from server A to server B. - Server B copies the file into a different folder.
Server A transfers the via SFTP:
Import-Module C:\WindowsPowerShell\Modules\Posh-SSH
Set-SFTPFile -SessionId $SFTPSession.SessionID -LocalFile $fileName -RemotePath $SftpTarget -Overwrite
Server B registers a event to unzip the file when the zip file is created:
$onCreated = Register-ObjectEvent $filePath Created -SourceIdentifier ListenFileCreated -Action{
# Copy a zip file
....
}
My problem is, the # Copy a zip file is triggered before the completion of the SFTP transferring. So when I tried to unzip the file I got "File incomplete" exception.
Anyone knows how to setup Register-ObjectEvent to only trigger when the file is completed, or other ways to check whether a file is in use?