title: How to upload yesterday file to SFTP using .bat file and WinSCP?
body: <p>This is my code getting the server date yesterday.</p>
  
  <pre><code>for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
  set "YY=%dt:~2,2%" &amp; set "YYYY=%dt:~0,4%" &amp; set "MM=%dt:~4,2%" &amp; set /A "DD=(%dt:~6,2%)-1"
  set datestamp=%YYYY%%MM%%DD%
  set RunDate=%datestamp%
  </code></pre>
  
  <hr>
  
  <p>However, I'm trying to add this condition in this syntax:</p>
  
  <pre><code>"C:\Program Files (x86)\WinSCP\winscp.com" /console ^
    /command "open sftp://Username:Password]@port" "cd /Dir" "put Dir\.CSV file" pause exit 
  </code></pre>
  
  <hr>
  
  <p>So it will be:</p>
  
  <pre><code>C:\Program Files (x86)\WinSCP\winscp.com /console /command 
  open sftp://USER:PASS]@IP
  cd Dir
  @echo off
  setlocal
  del Dir\Script.txt
  echo User&gt;&gt;Dir\Script.txt
  echo Pass&gt;&gt;Dir\Script.txt
  echo passive&gt;&gt;Dir\Script.txt
  echo prompt&gt;&gt;Dir\Script.txt
  echo cd Dir&gt;&gt;Dir\Script.txt
  echo binary&gt;&gt;Dir\Script.txt 
  
  for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do 
  set 
  "dt=%%a"
  set "YY=%dt:~2,2%" &amp; set "YYYY=%dt:~0,4%" &amp; set "MM=%dt:~4,2%" &amp; set /A "DD=
  (%dt:~6,2%)-1"
  set datestamp=%YYYY%%MM%%DD%
  set RunDate=%datestamp%
  echo %RunDate%
  echo put Dir_%RunDate%.csv&gt;&gt;Dir\Script.txt
  
  echo close&gt;&gt;Dir\Script.txt
  
  
  pause 
  exit  /b
  </code></pre>
  
  <hr>
  
  <p>I'm trying to add the variable: <code>%RunDate%</code> to any <code>.csv</code> file (Yesterday date with format) to upload it to the SFTP. </p>