title: Downloading file from server over FTP
body: <p>I need to download a file that is placed in a folder called abc_20140221_123456 in server1 over ftp to my local directory. The problem is that the <strong>last six characters of the folder name are not fixed.</strong> For example today the folder may be called abc_20140221_123456 and tomorrow it might be called abc_20140221_234567. I am having problems in writing an automation batch script to do the same.</p>
  
  <p>Here's the script I am working on:</p>
  
  <pre><code>@echo off
  setlocal
  set buildDate=%DATE:~0,10%
  set dateStr=%buildDate:~6,4%%buildDate:~3,2%%buildDate:~0,2%
  set folderName=abc_%dateStr%_
  echo open server1&gt;&gt;file.tmp 
  echo username&gt;&gt;file.tmp
  echo password&gt;&gt;file.tmp
  echo prompt&gt;&gt; file.tmp
  echo binary&gt;&gt;file.tmp
  echo lcd E:\&gt;&gt;file.tmp
  :: Not sure how to cd to abc_20140221_* from here
  echo get filename.txt&gt;&gt;file.tmp
  echo y&gt;&gt;file.tmp
  echo disconnect&gt;&gt;file.tmp
  echo bye&gt;&gt;file.tmp
  ftp -i -s:file.tmp
  pause
  </code></pre>
  
  <p>I know that I can loop through directories using for like this:</p>
  
  <pre><code>for /d %%d in (' %path%/*%folderName%* ') do (
  echo get filename.txt&gt;&gt;file.tmp
  echo y&gt;&gt;file.tmp
  )
  </code></pre>
  
  <p>But "for" doesn't work inside ftp>. </p>
  
  <p>Any help is highly appreciated. Thanks.</p>