title: SFTP directory listing to local txt file
body: <p>I am having problems with trying to list a directory on my sftp server to a local .txt file.</p>
  
  <p>I need to use commandline. So i have figured out putty is just about the only client that can do this.</p>
  
  <p>So, using putty i started working towards figuring it out. I managed to get as far as to listing the directory i want (In both psftp, and pscp) which are the putty sftp client and the putty secure file up/download client.</p>
  
  <p>Using this script when pscp.exe (For a .bat script):</p>
  
  <pre><code>start /WAIT D:\pscp.exe -sftp -v -batch -pw password -ls username@server.host:/directory/subdirectory/subdirectory
  </code></pre>
  
  <p>This lists the directory. I tried adding " C:\filelist.txt" to the end of it, but that only created an empty local file, the directories didn't get listed in it.</p>
  
  <p>And using this script when psftp.exe (For .bat script too):</p>
  
  <pre><code>start /WAIT D:\psftp.exe username@server.host -v -be -bc -batch -pw password -b D:\listcommands.scr
  </code></pre>
  
  <p>Where listcommand.scr is called to initiate more commands in the psftp, it contains:</p>
  
  <pre><code>ls /directory/subdirectory/subdirectory &gt; D:\listdir.txt
  </code></pre>
  
  <p>But neither will write the directory listing to the local .txt file. The psftp.exe command doesn't even create an empty .txt file like the pscp.exe command does. The listcommands.scr command doesn't work without the ">" either.</p>
  
  <p>Thanks to anyone who has any help to offer in regards to this.</p>