<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#***************************************************************************
#                                  _   _ ____  _
#  Project                     ___| | | |  _ \| |
#                             / __| | | | |_) | |
#                            | (__| |_| |  _ &lt;| |___
#                             \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2022, Daniel Stenberg, &lt;daniel@haxx.se&gt;, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
%file_chmod1 = (
  'name'      =&gt; 'chmod1',
  'content'   =&gt; "This file should have permissions 444\n",
  'perm'      =&gt; 'r--r--r--',
  'time'      =&gt; 'Jan 11 10:00',
  'dostime'   =&gt; '01-11-10  10:00AM',
);

%file_chmod2 = (
  'name'      =&gt; 'chmod2',
  'content'   =&gt; "This file should have permissions 666\n",
  'perm'      =&gt; 'rw-rw-rw-',
  'time'      =&gt; 'Feb  1  8:00',
  'dostime'   =&gt; '02-01-10  08:00AM',
);

%file_chmod3 = (
  'name'      =&gt; 'chmod3',
  'content'   =&gt; "This file should have permissions 777\n",
  'perm'      =&gt; 'rwxrwxrwx',
  'time'      =&gt; 'Feb  1  8:00',
  'dostime'   =&gt; '02-01-10  08:00AM',
);

%file_chmod4 = (
  'type'      =&gt; 'd',
  'name'      =&gt; 'chmod4',
  'content'   =&gt; "This file should have permissions 001\n",
  'perm'      =&gt; '--S--S--t',
  'time'      =&gt; 'May  4  4:31',
  'dostime'   =&gt; '05-04-10  04:31AM'
);

%file_chmod5 = (
  'type'      =&gt; 'd',
  'name'      =&gt; 'chmod5',
  'content'   =&gt; "This file should have permissions 110\n",
  'perm'      =&gt; '--s--s--T',
  'time'      =&gt; 'May  4  4:31',
  'dostime'   =&gt; '05-04-10  04:31AM'
);

%link_link = (
  'type'      =&gt; 'l',
  'name'      =&gt; 'link -&gt; file.txt',
  'size'      =&gt; '8',
  'perm'      =&gt; 'rwxrwxrwx',
  'time'      =&gt; 'Jan  6  4:42'
);

%link_link_absolute = (
  'type'      =&gt; 'l',
  'name'      =&gt; 'link_absolute -&gt; /data/ftp/file.txt',
  'size'      =&gt; '15',
  'perm'      =&gt; 'rwxrwxrwx',
  'time'      =&gt; 'Jan  6  4:45'
);

%dir_dot = (
  'type'      =&gt; "d",
  'name'      =&gt; ".",
  'hlink'     =&gt; "4",
  'time'      =&gt; "Apr 27  5:12",
  'size'      =&gt; "20480",
  'dostime'   =&gt; "04-27-10  05:12AM",
  'perm'      =&gt; "rwxrwxrwx"
);

%dir_ddot = (
  'type'      =&gt; "d",
  'name'      =&gt; "..",
  'hlink'     =&gt; "4",
  'size'      =&gt; "20480",
  'time'      =&gt; "Apr 23  3:12",
  'dostime'   =&gt; "04-23-10  03:12AM",
  'perm'      =&gt; "rwxrwxrwx"
);

%dir_weirddir_txt = (
  'type'      =&gt; "d",
  'name'      =&gt; "weirddir.txt",
  'hlink'     =&gt; "2",
  'size'      =&gt; "4096",
  'time'      =&gt; "Apr 23  3:12",
  'dostime'   =&gt; "04-23-10  03:12AM",
  'perm'      =&gt; "rwxr-xrwx"
);

%dir_UNIX = (
  'type'      =&gt; "d",
  'name'      =&gt; "UNIX",
  'hlink'     =&gt; "11",
  'size'      =&gt; "4096",
  'time'      =&gt; "Nov 01  2008",
  'dostime'   =&gt; "11-01-08  11:11AM",
  'perm'      =&gt; "rwx--x--x"
);

%dir_DOS = (
  'type'      =&gt; "d",
  'name'      =&gt; "DOS",
  'hlink'     =&gt; "11",
  'size'      =&gt; "4096",
  'time'      =&gt; "Nov 01  2008",
  'dostime'   =&gt; "11-01-08  11:11AM",
  'perm'      =&gt; "rwx--x--x"
);

%dir_dot_NeXT = (
  'type'      =&gt; "d",
  'name'      =&gt; ".NeXT",
  'hlink'     =&gt; "4",
  'size'      =&gt; "4096",
  'time'      =&gt; "Jan 23  2:05",
  'dostime'   =&gt; "01-23-05  02:05AM",
  'perm'      =&gt; "rwxrwxrwx"
);

%file_empty_file_dat = (
  'name'      =&gt; "empty_file.dat",
  'content'   =&gt; "",
  'perm'      =&gt; "rw-r--r--",
  'time'      =&gt; "Apr 27 11:01",
  'dostime'   =&gt; "04-27-10  11:01AM"
);

%file_file_txt = (
  'name'      =&gt; "file.txt",
  'content'   =&gt; "This is content of file \"file.txt\"\n",
  'time'      =&gt; "Apr 27 11:01",
  'dostime'   =&gt; "04-27-10  11:01AM",
  'perm'      =&gt; "rw-r--r--"
);

%file_someothertext_txt = (
  'name'      =&gt; "someothertext.txt",
  'content'   =&gt; "Some junk ;-) This file does not really exist.\n",
  'time'      =&gt; "Apr 27 11:01",
  'dostime'   =&gt; "04-27-10  11:01AM",
  'perm'      =&gt; "rw-r--r--"
);

%lists = (
  '/fully_simulated/' =&gt; {
    'files'   =&gt; [ \%dir_dot, \%dir_ddot, \%dir_DOS, \%dir_UNIX ],
    'eol'     =&gt; "\r\n",
    'type'    =&gt; "unix"
  },
  '/fully_simulated/UNIX/' =&gt; {
    'files'   =&gt; [ \%dir_dot, \%dir_ddot,
                   \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
                   \%file_empty_file_dat, \%file_file_txt,
                   \%link_link, \%link_link_absolute, \%dir_dot_NeXT,
                   \%file_someothertext_txt, \%dir_weirddir_txt ],
    'eol'     =&gt; "\r\n",
    'type'    =&gt; 'unix'
  },
  '/fully_simulated/DOS/' =&gt; {
    'files'   =&gt; [ \%dir_dot, \%dir_ddot,
                   \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
                   \%file_empty_file_dat, \%file_file_txt,
                   \%dir_dot_NeXT, \%file_someothertext_txt, \%dir_weirddir_txt ],
    'eol'     =&gt; "\r\n",
    'type'    =&gt; 'dos'
  }
);

sub ftp_createcontent($) {
  my (%list) = @_;

  $type = $$list{'type'};
  $eol  = $$list{'eol'};
  $list_ref = $$list{'files'};

  my @diroutput;
  my @contentlist;
  if($type eq "unix") {
    for(@$list_ref) {
      my %file = %$_;
      my $line = "";
      my $ftype  = $file{'type'}  ? $file{'type'}  : "-";
      my $fperm  = $file{'perm'}  ? $file{'perm'}  : "rwxr-xr-x";
      my $fuser  = $file{'user'}  ? sprintf("%15s", $file{'user'})   : "ftp-default";
      my $fgroup = $file{'group'} ? sprintf("%15s", $file{'group'})  : "ftp-default";
      my $fsize = "";
      if($file{'type'} eq "d") {
        $fsize = $file{'size'} ? sprintf("%7s", $file{'size'}) : sprintf("%7d", 4096);
      }
      else {
        $fsize = sprintf("%7d", length $file{'content'});
      }
      my $fhlink = $file{'hlink'} ? sprintf("%4d",  $file{'hlink'})  : "   1";
      my $ftime  = $file{'time'}  ? sprintf("%10s", $file{'time'})   : "Jan 9  1933";
      push(@contentlist, "$ftype$fperm $fhlink $fuser $fgroup $fsize $ftime $file{'name'}$eol");
    }

    return @contentlist;
  }
  elsif($type =~ /^dos$/) {
    for(@$list_ref) {
      my %file = %$_;
      my $line = "";
      my $time = $file{'dostime'} ? $file{'dostime'} : "06-25-97  09:12AM";
      my $size_or_dir;
      if($file{'type'} =~ /^d$/) {
        $size_or_dir = "      &lt;DIR&gt;         ";
      }
      else {
        $size_or_dir = sprintf("%20d", length $file{'content'});
      }
      push(@contentlist, "$time $size_or_dir $file{'name'}$eol");
    }
    return @contentlist;
  }
}

sub wildcard_filesize($$) {
  my ($list_type, $file) = @_;
  $list = $lists{$list_type};
  if($list) {
    my $files = $list-&gt;{'files'};
    for(@$files) {
      my %f = %$_;
      if ($f{'name'} eq $file) {
        if($f{'content'}) {
          return length $f{'content'};
        }
        elsif ($f{'type'} ne "d"){
          return 0;
        }
        else {
          return -1;
        }
      }
    }
  }
  return -1;
}
sub wildcard_getfile($$) {
  my ($list_type, $file) = @_;
  $list = $lists{$list_type};
  if($list) {
    my $files = $list-&gt;{'files'};
    for(@$files) {
      my %f = %$_;
      if ($f{'name'} eq $file) {
        if($f{'content'}) {
          return (length $f{'content'}, $f{'content'});
        }
        elsif ($f{'type'} ne "d"){
          return (0, "");
        }
        else {
          return (-1, 0);
        }
      }
    }
  }
  return (-1, 0);
}

sub ftp_contentlist {
  my $listname = $_[0];
  $list = $lists{$listname};
  return ftp_createcontent(\$list);
}
</pre></body></html>