title: Moving and renaming downloaded files to another directory in WinSCP scripting
body: <p>I have created the following files that do specific tasks as indicated:</p>
  
  <ul>
  <li><code>DataCollection.bat</code> - Opens WinSCP and runs command in the <code>dailyimport.txt</code></li>
  <li><code>Dailyimport.txt</code> - logs into remote FTP site and retrieves three <code>*.csv</code> files, renaming them in the destination folder.</li>
  </ul>
  
  <p>Later a PHP script is executed to import the data in the three CSV files into my database.</p>
  
  <p>What I need to do now, and where I am having a problem is:</p>
  
  <ul>
  <li>Moving the downloaded files (Now on local host) into a new directory, and again renaming them, by keeping the file name and adding a timestamp.</li>
  <li>Moving the files on the FTP server into a new directory.</li>
  </ul>
  
  <p>Please see my code I have below:</p>
  
  <p>DataCollection.bat:</p>
  
  <pre><code>@echo off
  winscp.com /script=dailyimport.txt
  if %ERRORLEVEL% neq 0 goto error
  
  echo Upload succeeded, moving local files
  move "C:\DataImport\modules_flat_file_footer.csv" "C:\DataImport\Imported\modules_flat_file_footer.csv.%TIMESTAMP#yyyymmss%"
  exit /b 0
  
  :error
  echo Upload failed, keeping local files
  exit /b 1
  </code></pre>
  
  <p>dailyimport.txt:</p>
  
  <pre><code># Connect
  open ftp://myftpdetails/
  # Change remote directory
  cd /downloads/MySQL
  # Force binary mode transfer
  option transfer binary
  # Download file to the local directory
  get modules_flat_file_footer_*.csv "C:\DataImport\modules_flat_file_footer.csv"
  
  # Disconnect
  close
  # Exit WinSCP
  exit
  </code></pre>