# Writing command line outputs to local files



## ajetrumpet (Nov 1, 2009)

hello all,

I have asked this on a couple of forums, but I thought I would check here too. I can write the following to output the DOS list of files and folders of the current directory to a text file:

```
dir /b > dirs.txt
```
this works beautifully when I'm in CMD.EXE mode, but not in FTP mode. Does anyone know if the same thing is possible in FTP mode? when I write this same thing in that mode, I get this message:

```
USAGE: remote directory local file.
```
can anyone help me out with this one. thanks!


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!

I'm assuming you are wanting to capture a listing of the folder on the FTP server, not a local folder.

Would be nice if the USAGE: message would include an example or two, and showed what was optional.
It is just as the usage says, and is almost the same as in the command prompt.
In the command prompt, the usage is:
*Dir [switches] [path] > file*
You're using
*Dir /B >dirs.txt*
You aren't specifying a path, so the local folder is assumed.
In FTP it's the same minus the redirection symbol >:
remote directory=path
local file=file
But the switches are different. In an FTP shell, it's more or less a Unix shell, and *Dir* is an alias for *ls*, so google *man ls* to get the *Man*ual page for the *ls* command. Note that some options may not be the same with your particular FTP server.
Here's just one:http://ss64.com/bash/ls.html

So for a bare listing saved to the local file dirs.txt, use this:
*Dir [switches] [remote directory]  [local file]*
*DIR -C1 dirs.txt*

The switch means display in *C*olumns (3 names per line) and the *1* changes that to one file per line (that is a one, not a lowercase L).
The *C* must be capitalized. A lowercase *c* sorts by modified(changed) time.

HTH

Jerry


----------



## ajetrumpet (Nov 1, 2009)

hey Jerry. how are you? thanks a lot for your reply. Your response got me to the point that I am at right now. if you don't mind I have another question for you...

I am capturing everything just perfectly, but there is a problem I can't get my head around. I have this code for example:

```
Dim vPath As String
      Dim vFTPServ As String
      Dim fNum As Long
      
      vPath = "C:"
      vFTPServ = "www.domain.com"
      fNum = FreeFile()
      
      Open vPath & "\FtpComm.txt" For Output As #fNum
      Print #1, "USER myUN" ' your login
      Print #1, "pass" ' your password
      Print #1, "dir " & Me.namefield & " c:\test.txt"
      Print #1, "close"
      Print #1, "quit"
      Close
      
      Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbHide
```
i am doing this everytime I want to view the contents of the TEST text file. my question is, is there a way that I can leave the FTP session open, and keep printing lines in the FTPCOMM file and keep executing DOS commands one at a time this way instead of opening and closing the connection each time? thanks!


----------



## TheOutcaste (Aug 8, 2007)

Once you start the FTP session, you can't add lines to the script file, so you would have to close then open another session.
You can leave out the quit command, and use the script to open the session, then send commands to the FTP window using the *SendKeys* command, but I don't know enough VB to tell you how to do it. Not sure if *SendKeys* will work with a hidden window though.

Most FTP servers will disconnect you after a period of inactivity, so you would need some sort of keep alive routine as well.


----------



## ajetrumpet (Nov 1, 2009)

thanks Jerry. I'll give it a try or try and figure out how to do it. I am doing seperate sessions right now, which is not a good thing because the updates on my local machine take about 5 seconds to complete, and my hourglass in VBA doesn't work when I'm doing this either. So....the user would not know when to move onto the next action, but i can't have it take that long, so I'll try. thanks again man!


----------

