Windows ftp command: How to count number of files in remote directory?
6,197
- Save remote file list to a file;
- Count number of lines in the file.
@echo off
echo open ftp.example.com>ftp.txt
echo user>>ftp.txt
echo password>>ftp.txt
echo ls /remote/path files.txt>>ftp.txt
echo bye>>ftp.txt
ftp -s:ftp.txt
set /a LINES=0
for /f %%j in ('type files.txt^|find "" /v /c ') do set /a LINES=%%j
del files.txt
del ftp.txt
echo Number of files: %LINES%
As others have commented, using PowerShell script would be more elegant and reliable though.
Related videos on Youtube
Author by
KAE
Updated on September 18, 2022Comments
-
KAE over 1 year
When I use the Windows
ftp
command at the command window which I think is the DOSftp
command, is there a way to count the number of files in the remote directory? That way I can check that I ftp'ed them all. I am stuck using Window 7 built-in commands and can't use a different program.-
sean christe almost 8 yearsW7 has Powershell installed. I would suggest using that.
-
KAE almost 8 yearsPowerShell was new to me, and if anyone else wants background: What is PowerShell, digitalcitizen.life/… , example of using it to count ftp files, salvoz.com/blog/2013/07/21/powershell-ftp-scripts
-
-
ashleedawg over 3 yearsthe question says "count the files in a directory", not "count the lines in a file"
-
Martin Prikryl over 3 years@ashleedawg Sure. And the answer shows how to do that by saving the file list to a file and counting the lines in the file. It wouldn't be the accepted answer, if it did not answer the question. If you have a better way how to count the files in a batch file, please post your own answer.