title: Upload with VBA via sFTP & FTP, log outputs to detect errors
body: <p>I wrote the following code to try and upload to two different servers one via ftp and one via sftp.</p>
  
  <p>I would like to know if there is a better way to upload via SFTP because the current method as I have it doesn't trigger the FTP error if it fails on any part.</p>
  
  <p>I guess a work around and something I would like to have is for both of them to log the output to a text file and then from that I can see what the error was manually and if I want setup a simple read log, check error, if x do y...</p>
  
  <pre><code>        On Error GoTo Err_FTPFile
  
          ' UPLOAD FIRST FILE VIA FTP
  
          'Build up the necessary parameters
          sHost = "ftp.server.com"
          sUser = "user@server.com"
          sPass = "password"
          sSrc = """" + Environ("TEMP") + "\" + file + ".txt" + """"
          sDest = "/remote/folder/"
  
          'Write the FTP commands to a file
          iFNum = FreeFile
          sFTPCmds1 = Environ("TEMP") &amp; "\" &amp; "FTPCmd1.tmp"
          Open sFTPCmds1 For Output As #iFNum
              Print #iFNum, "ftp"
              Print #iFNum, "open " &amp; sHost
              Print #iFNum, sUser
              Print #iFNum, sPass
              Print #iFNum, "cd " &amp; sDest
              Print #iFNum, "put " &amp; sSrc
              Print #iFNum, "disconnect"
              Print #iFNum, "bye"
          Close #iFNum
  
          'Upload the file
          Shell Environ("WINDIR") &amp; "\System32\ftp.exe -s:" &amp; sFTPCmds1
          Application.Wait (Now + TimeValue("0:00:10"))
  
  
          ' UPLOAD SECOND FILE VIA SFTP
  
          'Build up the necessary parameters
          sFTPDetails = "C:\psftp.exe -b C:\commands.tmp user@ex.server.com -pw password"
          sSrc = """" + Environ("TEMP") + "\" + file + ".txt" + """"
          sDest = "/remote/folder/"
  
          'Write the FTP commands to a file
          iFNum = FreeFile
          sFTPCmds2 = sFolder &amp; "\" &amp; "commands.tmp"
          Open sFTPCmds2 For Output As #iFNum
              Print #iFNum, "cd " &amp; sDest
              Print #iFNum, "put " &amp; sSrc
              Print #iFNum, "quit"
              Print #iFNum, "bye"
          Close #iFNum
  
          'Upload the file
          Call Shell(sFTPDetails, vbNormalFocus)
          Application.Wait (Now + TimeValue("0:00:10"))
  
  Exit_FTPFile:
          On Error Resume Next
          Close #iFNum
  
          'Delete the temp FTP command file
          Kill sFTPCmds1
          Kill sFTPCmds2
          Kill Environ("TEMP") + file + ".txt"
  
          GoTo ContinuePoint
  
  Err_FTPFile:
          Shell "C:\FailPushBullet.exe"
          MsgBox Err.Number &amp; " - " &amp; Err.Description &amp; " Failed.", vbOKOnly, "Error"
          GoTo ContinuePoint
  
  ContinuePoint:
  ' Do stuff
  </code></pre>
  
  <p>I ideally would like the SFTP one at the bottom to work and function exactly like the FTP one from above.</p>
  
  <p>I tried the following and this runs:</p>
  
  <pre><code>    sClient = "C:\psftp.exe"
      sArgs = "user@website.com -pw passexample -b C:\commands.tmp"
      sFull = sClient &amp; " " &amp; sArgs
  
      sSrc = """" + Environ("TEMP") + "\" + "test" + ".txt" + """"
      sDest = "folder"
  
      'Write the FTP commands to a text file
      iFNum = FreeFile
      sFTPCmds = "C:\" &amp; "commands.tmp"
      Open sFTPCmds For Output As #iFNum
          Print #iFNum, "cd " &amp; sDest
          Print #iFNum, "put " &amp; sSrc
          Print #iFNum, "quit"
          Print #iFNum, "bye"
      Close #iFNum
  
      'Upload the file
      Call Shell(sFull, vbNormalFocus)
  </code></pre>
  
  <p>But if I change the sArgs to <code>sArgs = "user@website.com -pw passexample -b C:\commands.tmp 1&gt; log.txt"</code> it doesn't run, it just closes without doing anything. I thought <code>1&gt; log.txt</code> is supposed to put the output into a file</p>