title: Powershell script to download file from FTPS server
body: <p>I have seen mixed posts but nothing definitive and recent.  I am running Filezilla Server FTPS Explicit TLS.  I need a Powershell script that when run will securely connect to my server across the internet and download a specific file.  Does the below code looks good minus the TLS, and can someone help me finish it? I think all of the commands I would need would be from here <a href="https://winscp.net/eng/docs/library_sessionoptions#ftpsecure" rel="nofollow noreferrer">https://winscp.net/eng/docs/library_sessionoptions#ftpsecure</a></p>
  
  <pre><code>    # Load WinSCP .NET assembly
  Add-Type -Path "WinSCPnet.dll"
  
  # Setup session options
  $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
      Protocol = [WinSCP.Protocol]::Ftp
      HostName = "ftp.example.com"
      UserName = "user"
      Password = "mypassword"
  }
  
  $session = New-Object WinSCP.Session
  
  try
  {
      # Connect
      $session.Open($sessionOptions)
  
      # Download files
      $session.GetFiles("/directory/to/download/*", "C:\target\directory\*").Check()
  }
  finally
  {
      # Disconnect, clean up
      $session.Dispose()
  }    
  </code></pre>