title: How do I query a file on FTP server in PowerShell to determine if an upload is required?
body: <p>The project is an MVC website coded and built using VS2017 and (on premises) TFS2017.  The Build Definition is currently working and publishing to the staging location upon check-in.</p>
  
  <p>The PowerShell script below, derived from <a href="https://www.kittell.net/code/powershell-ftp-upload-directory-sub-directories/" rel="nofollow noreferrer">David Kittle's website</a>, is being used but it uploads all files every time.  I abbreviated the listing using comments to focus on the part of the script for which I'd like to ask for help/guidance.</p>
  
  <pre><code># Setup the FTP connection, destination URL and local source directory
  # Put the folders and files to upload into $Srcfolders and $SrcFiles
  # Create destination folders as required
  
  # start file uploads
  foreach($entry in $SrcFiles)
  {
      #Create full destination filename from $entry and put it into $DesFile
      $uri = New-Object System.Uri($DesFile) 
  
      #NEED TO GET THE REMOTE FILE DATA HERE TO TEST AGAINST THE LOCAL FILE
      If (#perform a test to see if the file needs to be uploaded)
          { $webclient.UploadFile($uri, $SrcFullname) }
  }
  </code></pre>
  
  <p>In the last few lines of the script above I need to determine if a source file requires upload.  I am assuming I can check the time stamp to determine this.  So;</p>
  
  <p>If my assumption is wrong, please advise the best way to check for a required upload.</p>
  
  <p>If my assumption is correct, how do I (1) retrieve the time stamp from the remote server and then (2) make the check against the local file?</p>