title: Status Code 3 at the end of WinSCP SFTP upload
body: <p>I have a Java server technology (Ignition by Inductive Automation specifically) that calls a batch file that is meant to use WinSCP to transfer some text files overnight to our customer.  It is not working and I am not sure why.</p>
  <p>Here is the batch file – actual information has been changed so any typos are not representative of actual batch file.  Note that</p>
  <pre><code>set sftpPathData=C:\SFTP\Up\Data*.txt.gpg
  echo sftpPathData
  FOR /F &quot;delims=|&quot; %%I IN ('DIR %sftpPathData% /B /O:D') DO SET NewestDataFile=%%I
  echo NewestDataFile is %NewestDataFile%
  set filePathData=C:\SFTP\Up\%NewestDataFile%
  &quot;C:\Program Files (x86)\WinSCP\WinSCP.exe&quot; SiteName /log=c:\temp\winscp2.log /loglevel=* /privatekey=C:\Keys\key_nopassphrase.ppk /command &quot;open sftp://User:password.url.net:6055/&quot; &quot;cd firstdirectory\secondDirectory\&quot;  &quot;put %filePathData%&quot; &quot;close&quot;
  exit /b
  </code></pre>
  <p>I call this via a Python (technically Jython) subprocess call and log the stderr, but I don't see any issues there – nothing in my logs the past month come through for the stderr.</p>
  <p>In the WinSCP logs this is what I see – I am truncating a lot but showing what I believe is relevant, it logs in and attempts to copy the file over but I see a <code>Status code: 3</code> whereas previously when it was working this was a <code>Status code: 0</code>.</p>
  <p>Logs from this morning -</p>
  <pre><code>. 2022-01-07 04:10:02.120 Copying &quot;C:\SFTP\Up\Data01072020.txt.gpg&quot; to remote directory started.
  . 2022-01-07 04:10:02.120 Binary transfer mode selected.
  . 2022-01-07 04:10:02.120 Opening remote file.
  &gt; 2022-01-07 04:10:02.120 Type: SSH_FXP_OPEN, Size: 76, Number: 771
  &lt; 2022-01-07 04:10:02.520 Type: SSH_FXP_HANDLE, Size: 10, Number: 771
  &gt; 2022-01-07 04:10:02.521 Type: SSH_FXP_WRITE, Size: 4118, Number: 1286
  . 2022-01-07 04:10:02.523 16 skipped SSH_FXP_WRITE, SSH_FXP_READ, SSH_FXP_DATA and SSH_FXP_STATUS packets.
  &gt; 2022-01-07 04:10:02.523 Type: SSH_FXP_CLOSE, Size: 10, Number: 5636
  &gt; 2022-01-07 04:10:02.523 Type: SSH_FXP_SETSTAT, Size: 72, Number: 1033
  &lt; 2022-01-07 04:10:02.547 Type: SSH_FXP_STATUS, Size: 49, Number: 1286
  &lt; 2022-01-07 04:10:02.561 Type: SSH_FXP_STATUS, Size: 49, Number: 1542
  &lt; 2022-01-07 04:10:02.561 Type: SSH_FXP_STATUS, Size: 49, Number: 1798
  &lt; 2022-01-07 04:10:02.564 Type: SSH_FXP_STATUS, Size: 49, Number: 2054
  &lt; 2022-01-07 04:10:02.565 Type: SSH_FXP_STATUS, Size: 49, Number: 2310
  &lt; 2022-01-07 04:10:02.579 Type: SSH_FXP_STATUS, Size: 49, Number: 2566
  &lt; 2022-01-07 04:10:02.583 Type: SSH_FXP_STATUS, Size: 49, Number: 2822
  &lt; 2022-01-07 04:10:02.586 Type: SSH_FXP_STATUS, Size: 49, Number: 3078
  &lt; 2022-01-07 04:10:02.587 Type: SSH_FXP_STATUS, Size: 49, Number: 3334
  &lt; 2022-01-07 04:10:02.588 Type: SSH_FXP_STATUS, Size: 49, Number: 3590
  &lt; 2022-01-07 04:10:02.588 Type: SSH_FXP_STATUS, Size: 49, Number: 3846
  &lt; 2022-01-07 04:10:02.588 Type: SSH_FXP_STATUS, Size: 49, Number: 4102
  &lt; 2022-01-07 04:10:02.595 Type: SSH_FXP_STATUS, Size: 49, Number: 4358
  &lt; 2022-01-07 04:10:02.601 Type: SSH_FXP_STATUS, Size: 49, Number: 4614
  &lt; 2022-01-07 04:10:02.601 Type: SSH_FXP_STATUS, Size: 49, Number: 4870
  &lt; 2022-01-07 04:10:02.602 Type: SSH_FXP_STATUS, Size: 49, Number: 5126
  &lt; 2022-01-07 04:10:02.602 Type: SSH_FXP_STATUS, Size: 49, Number: 5382
  &lt; 2022-01-07 04:10:02.772 Type: SSH_FXP_STATUS, Size: 40, Number: 5636
  &lt; 2022-01-07 04:10:02.772 Status code: 0
  . 2022-01-07 04:10:02.772 Preserving timestamp [2022-01-07T09:00:01.000Z]
  &lt; 2022-01-07 04:10:02.807 Type: SSH_FXP_STATUS, Size: 176, Number: 1033
  &lt; 2022-01-07 04:10:02.807 Status code: 3
  . 2022-01-07 04:10:02.807 Transfer done: 'C:\SFTP\Up\Data01072020.txt.gpg' [65702]
  &gt; 2022-01-07 04:10:02.808 Script: close
  . 2022-01-07 04:10:02.808 Closing connection.
  . 2022-01-07 04:10:02.808 Sending special code: 12
  . 2022-01-07 04:10:02.808 Sent EOF message
  </code></pre>
  <p>When this was working this line -</p>
  <pre><code>&lt; 2022-01-07 04:10:02.807 Status code: 3
  </code></pre>
  <p>would appear as</p>
  <pre><code>&lt; 2022-01-07 04:10:02.807 Status code: 0
  </code></pre>
  <p>Any help or ability to point me in the right direction is greatly appreciated.  I see here <a href="https://winscp.net/eng/docs/sftp_codes" rel="nofollow noreferrer">https://winscp.net/eng/docs/sftp_codes</a> that 3 means</p>
  <blockquote>
  <p>Permission denied The user does not have sufficient permissions to perform the operation.</p>
  </blockquote>
  <p>The Java server technology that is running as a Windows Service that is calling the batch file is logged in as the Administrator account.</p>
  <p>Using the WinSCP GUI directly I am able to drag and drop files to the appropriate remote directory.</p>
  <p>I am at a loss.  Any information on how to fix this issue or perhaps a different way to do this with WinSCP (send the latest two files in a specific directory with a specific extension to the remote server via WinSCP once a day) would be greatly appreciated.</p>