1

I am trying to:

  1. Transfer a zip file from server A to server B.
  2. 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?

Ellaaaa
  • 11
  • 2
  • That could help : https://stackoverflow.com/questions/33958395/copy-file-on-creation-once-complete – Manu Nov 13 '17 at 12:21

0 Answers0