9

When using the DOS command FTP in Windows 7, I can use this FTP command to list recursively all files of the remote directory:

ftp> ls -R

I cannot get the output of ls -R to a local file, FTP keeps complaining about the syntax:

ftp> ls -R . save.txt
usage: ls remote-directory local-file

Can someone explain why, and how to get the result I wanted?

3 Answers 3

9

as far as i know once you are in the interactive ftp shell the output can't be captured.

but you can either pipe commands to the ftp command or specify a file with the commands (required if you need multiple commands, like specifying username/password)

then you redirect the std out to a file.

like this:

echo ls -R | ftp yourHostname > save.txt

or you place all your commands (lets say mycommands.txt) in a text file and call it with

ftp -s:mycommands.txt > save.txt

mycommmands.txt could look like this

user yourName yourPassword
open yourHostname
cd someDirectory
ls -R

(i couldn't test the second example right now, so let me know if it doesn't work)

2
  • Thanks. It doesn't work, there is an authentication error (using anonymous and email). However, against logic, this ftp command works "ls -R save.txt"
    – mins
    Jul 30, 2014 at 16:31
  • while the command above is correct, some FTP server-side implementation removed support for ls -R, see: support.microsoft.com/kb/2007929
    – malat
    Oct 30, 2014 at 10:39
8

Assuming you are using simple ftp via command line, Use dir command with -Rl option to search recursively and copy it to a file and then search the file using grep, find or whatever way is supported on your OS.

ftp> dir -Rl education.txt
output to local-file: education.txt? y
227 Entering Passive Mode (9,62,119,15,138,239)
150 Opening ASCII mode data connection for file list
226 Transfer complete
2
ftp> dir * Sample.txt

This worked for me.

1
  • Welcome to Super User. Your answer could use improvement by explaining why/how your solution fixes/addresses the OPs question. Also, from the looks of your command this won't create a recursive directory output as required by the OP. Apr 24, 2017 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .