Как проверить использование диска в ftp?

В дополнение к другим ответам sudo предоставляет регистрирующиеся услуги, таким образом, можно отслеживать то, какие команды были выполнены и кто. Это не в целях безопасности, так как злонамеренный пользователь, который получает sudo доступ, может вытереть журнал. Это очень полезно, хотя выяснить точно, что Вы или некоторый другой администратор сделали смутный следивший в 2:00 на прошлой неделе.

6
19.09.2016, 14:14
2 ответа

Вы могли использовать Perl. Из http://aplawrence.com/Unixart/perlnetftp.html:

#!/usr/bin/perl
my $param = $ARGV[0];
# required modules
 use Net::FTP;
 use File::Listing qw(parse_dir);

 sub getRecursiveDirListing
  {
      # create a new instance of the FTP connection
      my $ftp = Net::FTP->new("fftpserver", Debug=>0) or die("Cannot connect $!");
      # login to the server
      $ftp->login("username","password") or die("Login failed $!");

      # create an array to hold directories, it should be a local variable
      local @dirs = ();

      # directory parameter passed to the sub-routine
      my $dir = $_[0];

      # if the directory was passed onto the sub-routin, change the remote directory
      $ftp->cwd($dir) if($dir);

      # get the file listing
      @ls = $ftp->ls('-lR');

      # the current working directory on the remote server
      my $cur_dir = $ftp->pwd();

      my $totsize = 0;
      my $i = 0;
      my @arr = parse_dir(\@ls);
      my $arrcnt = scalar(@arr);
      if ($arrcnt == 0) {
        print "$cur_dir 0\n"; 
        $ftp->quit();
        exit 1;
      }
      else {
      # parse and loop through the directory listing
      foreach my $file (parse_dir(\@ls))
      {
          $i++;
          my($name, $type, $size, $mtime, $mode) = @$file; 
          $totsize = $totsize + $size if ($type eq 'f');

          print "$cur_dir $totsize\n" if ($i == $arrcnt);

          # recursive call to get the entries in the entry, and get an array of return values
#          @xx = getRecursiveDirListing ("$cur_dir/$name") if ($type eq 'd');
      }

      # close the FTP connection
      $ftp->quit();
      } 
      # merge the array returned from the recursive call with the current directory listing
#      return (@dirs,@xx);
  }
@y = getRecursiveDirListing ("$param");

Выполнять его:

$ ./getSize.pl <directory>
0
27.01.2020, 20:27

Я предлагаю, чтобы Вы использовали curlftpfs для монтирования репозитория FTP в файловой системе. Затем используйте традиционное du -shc . команда в папке Вы хотите знать использование диска.

7
27.01.2020, 20:27
  • 1
    Это работает только на каталоги ftp, которые читаемы. Каталоги, которые имеют "-x" полномочия, не будут "listable" curlftpfs. –  knb 07.11.2016, 15:59

Теги

Похожие вопросы