title: Transfer files from SFTP server using PowerShell Only if files doesn't exist
body: <p>Needing guidance to transfer files from an SFTP server to a network shared folder but only if the file name does not exist. </p>
  
  <p>I am able to do that now, but have been struggling with the same name files being over written on the folder transferring to and would prefer to skip same name file. </p>
  
  <p>Trying to get the powershell script to check if file exist, if so skip and do not transfer. Below is what I currently have and tried and does not seem to work, it over writes my existing files with the same name and that is not what I am seeking. I will continue doing further research as well.</p>
  
  <pre><code># Load the Assemblemy and setup the session properties
  try
  {
     # Load WinSCP . NET assembly
     Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
  
     # setup session options
     $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "0.0.0.0"
        UserName = "usernam01"
        Password = "Password"
        SshHostKeyFingerprint = "ssh-ed25519 256 **************************************"
    }
  
  
  $session = New-Object WinSCP.Session
  #end
  
  try
      {
          # Connect
          $session.Open($sessionOptions)
  
          # Download files
          $transferOptions = New-Object WinSCP.TransferOptions
          $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
          #$transferOptions.FileMask = "*&gt;=1D"
  
          $transferResult =
              $session.GetFiles("/home/*.csv", "\\fww\folder\", $False, $transferOptions)
          $remotePath = "\\fww\folder\"
          if ($session.FileExists($remotePath))
          {
               Write-Host "File $remotePath exists"
          }
  
          # Throw on any error
          $transferResult.Check()
  
          # Print results
          foreach ($transfer in $transferResult.Transfers)
          {
              Write-Host "Transfer of $($transfer.FileName) succeeded"
          }
      }
      finally
      {
          # Disconnect, clean up
          $session.Dispose()
      }
  
      exit 0
  }
  catch [Exception]
  {
      Write-Host "Error: $($_.Exception.Message)"
      exit 1
  </code></pre>