Solved

Count number of files in ftp account

Posted on 2004-08-04
14
20,335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 21

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 21

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 21

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

627 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