Solved

Count number of files in ftp account

Posted on 2004-08-04
14
19,968 Views
Last Modified: 2011-08-18
Hi,
I have an ftp account which I logged into win Win2000 using command prompt screen.
After I get to a directory where there are thousands of files, what is the command to count the # of files?
thank you,
phil
0
Comment
Question by:spoowiz
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 20

Expert Comment

by:tfewster
ID: 11718677
When connected to the server via FTP, try:
ls [remote-directory] [local-file]    # list the files & redirect the output to a file on your system
!wc -l [local-file]                          # Run a local shell process to count the lines in the file
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11730565
if your win2k ftp has no command for it, then you only can write a script to do it
BTW, to know the number of files while using ftp is useless, in most cases .. Or do you knwo a good reason?
0
 

Author Comment

by:spoowiz
ID: 11730757
tfewster - funny. didn't get the email from ee for your response.
suppose i'm already in the directory, please tell me the commands with examples?
i don't think "ls file" would do.

ahoffmann - why is number of files useless?

thanks
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 11733091
> why is number of files useless?
wrong question!
must be: what is it usefull for?
0
 
LVL 20

Expert Comment

by:tfewster
ID: 11734223
I don't know what it's useful for, but while connected via ftp, try:

ftp> ls . listing    
ftp> !wc -l listing

(If ftp gives you the prompt "output to local-file: listing?", type Y to confirm; Or you can disable prompting)

Note that the number `wc -l` returns will include the "total blocks" line returned by the ls command - If absolute accuracy is required, you could grep that out.
0
 

Author Comment

by:spoowiz
ID: 11736305
1.  >ls . listing
it says output truncated to 2000 matches. my other ftp program says the same thing. of course, i have a lot more than 2000 files.
2. >!wc -l listing
says: 'wc' is not recognized as an internal or external command,
operable program or batch file.

sorry, thought it was an easy thing. when solved, i will increase the points to 150.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11736437
ls . listing
!find /C " " listing
0
 
LVL 20

Assisted Solution

by:tfewster
tfewster earned 50 total points
ID: 11738763
> says output truncated to 2000 matches.
I don't  know if this is restriction of the ftp client (Win2000) or the server (One assumes the server is Unix, as you've posted the question here).

I can't see how you would do it within ftp. An alternative would be to create an "index" on the Unix box, e.g. `ls -l /path/to/directory | wc -l  > path/to/directory/index.txt` (maybe run regularly by cron) and use ftp to transfer the index file back to the W2K client.

> 'wc' is not recognized as an internal or external command,
Looks like ahoffmann saw straight away which way round you were doing this ;-)
0
 

Author Comment

by:spoowiz
ID: 11743816
ftp> ls . listing
200 PORT command successful
150 Connecting to port 29538
226 Output truncated to 2000 matches
ftp: 26480 bytes received in 0.63Seco
ftp> !find /C " " listing
FIND: Parameter format not correct

thanks for the try. above is the result. still not doing it. any other ideas?
ftp is on unix, i believe. the host is lunarpages.com
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 50 total points
ID: 11745606
> 226 Output truncated to 2000 matches
there is no way doing it with your combination of ftp client and ftp server.
0
 
LVL 1

Accepted Solution

by:
eric_j_kropf earned 50 total points
ID: 11755542
here is a nasty way of doing this (requires textpad.exe -

1.) Open a command window like normal and type ftp ftp_site > ftp.txt and hit enter. Where ftp_site is the ftp site where you are trying to get the listing. Also note where you are by default when you enter this commmand (ie C:\). This will redirect all output to a text file. Note that you will not see most of what is usually sent to the screen.
2.) Enter your login name. Hit Enter. Enter your password. Hit Enter.
3.) Type ls, hit enter, type bye, hit enter.
4.) At this point you will be back at the command prompt. Close the command prompt
5.) Open textpad, and then open the ftp.txt file in text pad.
6.) Edit the file to remove the FTP stuff at the top and bottom of the file.
7.) Click "View" and then "Line Numbers".

Hope this helps.
0
 

Author Comment

by:spoowiz
ID: 11756939
eric - good try. however, it still truncates to 2000 matches
i guess there's no solution.
for trying, i will award 50 points each. thanks.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11757305
whow, roughly 10 lines of description how to click some buttons, and the same result as with 2 simple command previously suggested 2 times.
No offence, just wondering ...
0
 

Author Comment

by:spoowiz
ID: 11758514
ahoffmann - sorry. it's because the other 2 lines with wc and find didn't work for me. i pasted the error and there was no response to it.
ftp> !find /C " " listing
FIND: Parameter format not correct

thank you for trying - and that' why i awarded 50 each.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now