title: Fatal: Server unexpectedly closed network connection
body: <p>I am trying to run following command from SQL Server Agent job to upload daily files to our FTP server. I tried the connection from a local utility like WinSCP 5.1.5 and connection to FTP succeeds without any problems, however connection attempt from script fails (following is code and error). Can someone help me in the right direction please?</p>
  
  <pre><code>$Error.Clear();
  $csv_file = "FilePath"
  $sftp_cmd = "C:\psftp.exe"
  
  $user = "TestUser"
  $pass = "pwd"
  $hst = "ftp3.xyz.com"
  $cmd = @(
    "put $csv_file",
    "bye"
  )
  
  $cmd | &amp; $sftp_cmd -pw $pass "$user@$hst" -batch
  </code></pre>
  
  <p>I am always getting an error</p>
  
  <blockquote>
    <p>Fatal: Server unexpectedly closed network connection.</p>
  </blockquote>