Solved

Count number of files in ftp account

Posted on 2004-08-04
14
20,193 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is a good general partitioning scheme for RHEL? 23 151
mobaxterm not able to change directory 28 378
centos commands 6 118
umask commands 5 19
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

752 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