title: How to save the ouput of shell command into a text file in VBA
body: <p>I have my code written like this,</p>
  
  <pre><code>  function ftpsend()
  
    Dim vPath As String
    Dim vFile As String
    Dim vFTPServ As String
    Dim fNum As Long
    Dim currntdir As String
  
    currntdir = ThisWorkbook.Path &amp; "\"
  
  
   vPath = currntdir
   vFile = currntdir &amp; "abc.xml"
   vFTPServ = "ftp.abc.com" 
  
    'Mounting file command for ftp.exe
    fNum = FreeFile()
   Open vPath &amp; "abc.txt" For Output As #fNum
   Print #1, "USER student" 
   Print #1, "xxxxx"
   Print #1, "send " &amp; vFile  
   Print #1, "close" 
   Print #1, "quit" 
   Close
  
  
   Shell "ftp -n -i -g -s:" &amp; vPath &amp; "abc.txt  " &amp; vFTPServ, vbNormalFocus
  
   end function 
  </code></pre>
  
  <p>Now, the shell command displays the output in the console ftp.exe as</p>
  
  <pre><code>Connected to ftp.abc.com
  220 Microsoft FTP service
  ftp&gt;USER student
  230 User logged in 
  ftp&gt;send D:abc.xml
  200 PORT command successful
  226 Transfer Complete 
  ftp&gt;close
  221&gt;Good bye
  ftp&gt;
  </code></pre>
  
  <p>I want this output from console as it is copied into a text file.Because,sometimes when the username and password are incorrect, it displays the message as " User not logged in ", "Login failed" in the console.I want to handle that error.Any other way to handle ftp errors? Please Help...</p>
  
  <p>Thanks in advance </p>