Solved

Count number of files in ftp account

Posted on 2004-08-04
14
20,113 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cygwin VIM in WIndows 2007: Unable to copy text to Windows 10 75
Access_log 17 163
Shell Script on AIX 7 142
Equivalent of WSUS for Solaris, AIX and Cisco devices 11 64
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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 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…
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.

735 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