Solved

Count number of files in ftp account

Posted on 2004-08-04
14
19,784 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

743 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

12 Experts available now in Live!

Get 1:1 Help Now