Topic "Collect list of filenames from remote directory"

Author Message


Please forgive me is this has been asked before (I am new to this).

Using the "ls" command to list the files in a remote directory is easy enough. But what I would like to do it to redirect the output of this command to a disk file in the local directory (Windows). In essence, I am just trying to get a list of the files in the remote directory to use for other purposes.

I have looked through the documentation, but I don't see anything that addresses redirection like this.

Any suggestions?

Thank you!


Sorry ... I forgot to mention that I am using WinSCP 4.16 with the SCP protocol in a scripting file at the command prompt in Windows. The remote computer runs Linux.


Never mind, I figured out how to do it from the command line when I call (I had assumed that I would have to do it from within the session).

And sorry for posting in the wrong forum ...


Hi Jerrys, i would like to get the list of filenames from remote directory in a text file. How do you manage to solve this issue?


I am on an Windows workstation and talking to a Linux remote server.

Basically, I set up a script file called "dolist.txt" containing the WINSCP commands that would list the contents of the all the directories on the remote server that I needed. Sort of like this:

ls ../usr/Current/Acrobat/
ls ../usr/Current/ASCII/
ls ../usr/Current/CSV/

Then I started WINSCP like this: <root>:<password>@<ipaddress> /script=dolist.txt > file.txt

(Make sure that you have in your search path ... it's easier that way)

Anyway, that put the entire output from all the "ls" commands into one file (file.txt)

It's not the nicest answer, but at least it got what I needed (for now).

I hope this helps you.

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26911
Location: Prague, Czechia
For this simple task you may try using plink from PuTTY package instead. It allows you to execute a shell command on remote machine. This way you can use formatting capabilities of unix ls command (e.g. to display names only)

plink <user>:<host> -pw <password> ls > file.txt

Last edited by martin on 2008-08-29; edited 1 time in total


Thank you! I'll take a look at Putty.

By the way, in reference to the topic of transferring files between two servers via a local workstation ...

I guess I am lucky ... from my Windows XP workstation, I have to deal with a Redhat Linux server as well as a Windows Server 2003 server. I found that if I make a mapped drive to a folder structure on the Windows server, WinSCP will treat that mapped drive as a local drive and the file transfers between the two remote servers works beautifully.

Just thought I would mention that in case someone else is in the same situation.

Thanks again for your help!

You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License