Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

FTP: how to get total number of files in directory

Hello Folks,

I prefer to use FTP from the command line but cannot figure out how--after having connected to a remote directory via ftp--to list the total number of files in that directory.

In Unix, I would do this:

% ls | wc -l

But hopefully there is also some way in FTP to do the same--but darned if I know how! I do see that FTP clients such as Transmit have this listing, but maybe that's a feature of the software and not ftp.

Thanks in advance for any suggestions/tips.

Doug

Mac OS X (10.5.2)

Posted on Apr 6, 2008 7:54 PM

Reply
21 replies

Apr 12, 2008 5:42 AM in response to Jun T.

. . . building on Kurt's and Jun's proposals,

cat script.ftp |ftp -n userID@isp.com|grep "^[d-]rw" |wc

The "d-" is in square brackets.

Inside the script.ftp file and assuming you have "write" permission to the remote directory, you can move files around with standard ftp commands. Not limited to just the "dir" command. Per Jun's proposal with this it would be possible to clean up the directory with either mget,mdel, or managing the data into sub-directories.

I also chose to quote the search string and filter grep responses to remove the possibility of picking up errant English text. This can be filtered differently by looking at the re_syntax man page.

Message was edited by: Hawaiian Scuba Dude

Message was edited by: Hawaiian Scuba Dude

Apr 13, 2008 4:59 PM in response to Kurt Sakaeda

So Kurt,

Say I have indeed setup a .netrc file as you suggested.

The following echo command "echo dir|ftp...", does that also need the userID, since the .netrc file already has that?

I've tried it as you suggested but this hasn't worked. Of course I substituted my FTP userID/password, and can confirm my .netrc file works successfully.

This seems a good method--so I'd like to try to figure this out.

Doug

Apr 16, 2008 5:55 PM in response to Doug Niven1

Dear Doug,

If your time permits, please copy & paste what happens when you type:

$ ftp userID@isp.com

The common errors are:

The .netrc has the wrong access settings. To fix them type:

$ chmod 400 .netrc

The format is wrong. A .netrc entry should like like this:

machine isp.com login userID password secretPassord

I look forward to seeing your message.

Your humble unix geek,



Kurt

Apr 17, 2008 6:40 AM in response to Kurt Sakaeda

Hi Kurt, here ya go (actual domain substituted with example.com):

G5 [~]: ftp doug@example.com
Connected to example.com.
220---------- Welcome to Pure-FTPd [TLS] ----------
220-Local time is now 06:39. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
331 User doug OK. Password required

FTP: how to get total number of files in directory

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.