如何计算FTP上的目录大小?

jlp*_*jlp 29 c# ftp

如何计算FTP文件夹的大小?你知道C#中的任何工具或编程方式吗?

小智 86

如果你有FileZilla,你可以使用这个技巧:

  • 单击要计算其大小的文件夹
  • 点击 Add files to queue

这将扫描所有文件夹和文件,并将它们添加到队列中.然后查看队列窗格及其下方(在状态栏上),您应该看到一条指示队列大小的消息.

  • 很好的解决方案.这样,您可以在不下载任何文件的情况下获取文件总数和总大小.如果有人对它感到好奇,Filezilla使用的[FTP命令](http://en.wikipedia.org/wiki/List_of_FTP_commands)是MLSD(递归地). (3认同)
  • 请注意,您需要在本地目录树窗格中选择有效目标(否则_Add files to queue_将显示为灰色). (3认同)

tan*_*ius 15

您可以将du命令lftp用于此目的,如下所示:

echo "du -hs ." | lftp example.com 2>&1
Run Code Online (Sandbox Code Playgroud)

这将打印当前目录的磁盘大小incl.所有子目录,以人类可读的格式(-h)和省略子目录的输出行(-s).stderr输出被重新路由到stdout,2>&1以便它包含在输出中.

但是,它lftp是一个仅限Linux的软件,所以要从C#中使用它,你需要在Cygwin中使用它.

lftp du命令文件是从丢失它的手册页,但与该lftp的外壳内可用的help du命令.作为参考,我在这里复制它的输出:

lftp :~> help du
Usage: du [options] <dirs>
Summarize disk usage.
 -a, --all             write counts for all files, not just directories
     --block-size=SIZ  use SIZ-byte blocks
 -b, --bytes           print size in bytes
 -c, --total           produce a grand total
 -d, --max-depth=N     print the total for a directory (or file, with --all)
                       only if it is N or fewer levels below the command
                       line argument;  --max-depth=0 is the same as
                       --summarize
 -F, --files           print number of files instead of sizes
 -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
 -H, --si              likewise, but use powers of 1000 not 1024
 -k, --kilobytes       like --block-size=1024
 -m, --megabytes       like --block-size=1048576
 -S, --separate-dirs   do not include size of subdirectories
 -s, --summarize       display only a total for each argument
     --exclude=PAT     exclude files that match PAT
Run Code Online (Sandbox Code Playgroud)

  • 对于认证回声"du -hs".| lftp -u user,密码hostname 2>&1 (2认同)
  • 如果您使用的是 Windows 10,您现在可以使用适用于 Linux 的 Windows 子系统 (WSL) (2认同)

zen*_*ngr 5

如果您只需要完成工作,那么 SmartFTP 可能会帮助您,它还有一个 PHP 和 ASP 脚本,可以通过递归遍历所有文件来获取总文件夹大小。

  • WinSCP 也这样做 (3认同)

Fra*_*urt 5

WinSCP(Microsoft Windows 上的免费 G​​UI):

在此处输入图片说明

在此处输入图片说明