1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at https://curl.se/docs/copyright.html.
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 # SPDX-License-Identifier: curl
23 ###########################################################################
31 use base qw(Exporter);
43 'content' => "This file should have permissions 444\n",
44 'perm' => 'r--r--r--',
45 'time' => 'Jan 11 10:00',
46 'dostime' => '01-11-10 10:00AM',
51 'content' => "This file should have permissions 666\n",
52 'perm' => 'rw-rw-rw-',
53 'time' => 'Feb 1 8:00',
54 'dostime' => '02-01-10 08:00AM',
59 'content' => "This file should have permissions 777\n",
60 'perm' => 'rwxrwxrwx',
61 'time' => 'Feb 1 8:00',
62 'dostime' => '02-01-10 08:00AM',
68 'content' => "This file should have permissions 001\n",
69 'perm' => '--S--S--t',
70 'time' => 'May 4 4:31',
71 'dostime' => '05-04-10 04:31AM'
77 'content' => "This file should have permissions 110\n",
78 'perm' => '--s--s--T',
79 'time' => 'May 4 4:31',
80 'dostime' => '05-04-10 04:31AM'
85 'name' => 'link -> file.txt',
87 'perm' => 'rwxrwxrwx',
88 'time' => 'Jan 6 4:42'
91 my %link_link_absolute = (
93 'name' => 'link_absolute -> /data/ftp/file.txt',
95 'perm' => 'rwxrwxrwx',
96 'time' => 'Jan 6 4:45'
103 'time' => "Apr 27 5:12",
105 'dostime' => "04-27-10 05:12AM",
106 'perm' => "rwxrwxrwx"
114 'time' => "Apr 23 3:12",
115 'dostime' => "04-23-10 03:12AM",
116 'perm' => "rwxrwxrwx"
119 my %dir_weirddir_txt = (
121 'name' => "weirddir.txt",
124 'time' => "Apr 23 3:12",
125 'dostime' => "04-23-10 03:12AM",
126 'perm' => "rwxr-xrwx"
134 'time' => "Nov 01 2008",
135 'dostime' => "11-01-08 11:11AM",
136 'perm' => "rwx--x--x"
144 'time' => "Nov 01 2008",
145 'dostime' => "11-01-08 11:11AM",
146 'perm' => "rwx--x--x"
154 'time' => "Jan 23 2:05",
155 'dostime' => "01-23-05 02:05AM",
156 'perm' => "rwxrwxrwx"
159 my %file_empty_file_dat = (
160 'name' => "empty_file.dat",
162 'perm' => "rw-r--r--",
163 'time' => "Apr 27 11:01",
164 'dostime' => "04-27-10 11:01AM"
167 my %file_file_txt = (
168 'name' => "file.txt",
169 'content' => "This is content of file \"file.txt\"\n",
170 'time' => "Apr 27 11:01",
171 'dostime' => "04-27-10 11:01AM",
172 'perm' => "rw-r--r--"
175 my %file_someothertext_txt = (
176 'name' => "someothertext.txt",
177 'content' => "Some junk ;-) This file does not really exist.\n",
178 'time' => "Apr 27 11:01",
179 'dostime' => "04-27-10 11:01AM",
180 'perm' => "rw-r--r--"
184 '/fully_simulated/' => {
185 'files' => [ \%dir_dot, \%dir_ddot, \%dir_DOS, \%dir_UNIX ],
189 '/fully_simulated/UNIX/' => {
190 'files' => [ \%dir_dot, \%dir_ddot,
191 \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
192 \%file_empty_file_dat, \%file_file_txt,
193 \%link_link, \%link_link_absolute, \%dir_dot_NeXT,
194 \%file_someothertext_txt, \%dir_weirddir_txt ],
198 '/fully_simulated/DOS/' => {
199 'files' => [ \%dir_dot, \%dir_ddot,
200 \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
201 \%file_empty_file_dat, \%file_file_txt,
202 \%dir_dot_NeXT, \%file_someothertext_txt, \%dir_weirddir_txt ],
208 sub ftp_createcontent {
211 my $type = $$list{'type'};
212 my $eol = $$list{'eol'};
213 my $list_ref = $$list{'files'};
217 if($type eq "unix") {
221 my $ftype = $file{'type'} ? $file{'type'} : "-";
222 my $fperm = $file{'perm'} ? $file{'perm'} : "rwxr-xr-x";
223 my $fuser = $file{'user'} ? sprintf("%15s", $file{'user'}) : "ftp-default";
224 my $fgroup = $file{'group'} ? sprintf("%15s", $file{'group'}) : "ftp-default";
226 if(exists($file{'type'}) && $file{'type'} eq "d") {
227 $fsize = $file{'size'} ? sprintf("%7s", $file{'size'}) : sprintf("%7d", 4096);
230 $fsize = sprintf("%7d", exists($file{'content'}) ? length $file{'content'} : 0);
232 my $fhlink = $file{'hlink'} ? sprintf("%4d", $file{'hlink'}) : " 1";
233 my $ftime = $file{'time'} ? sprintf("%10s", $file{'time'}) : "Jan 9 1933";
234 push(@contentlist, "$ftype$fperm $fhlink $fuser $fgroup $fsize $ftime $file{'name'}$eol");
239 elsif($type =~ /^dos$/) {
243 my $time = $file{'dostime'} ? $file{'dostime'} : "06-25-97 09:12AM";
245 if(exists($file{'type'}) && $file{'type'} =~ /^d$/) {
246 $size_or_dir = " <DIR> ";
249 $size_or_dir = sprintf("%20d", length $file{'content'});
251 push(@contentlist, "$time $size_or_dir $file{'name'}$eol");
257 sub wildcard_filesize {
258 my ($list_type, $file) = @_;
259 my $list = $lists{$list_type};
261 my $files = $list->{'files'};
264 if ($f{'name'} eq $file) {
266 return length $f{'content'};
268 elsif ($f{'type'} ne "d"){
280 sub wildcard_getfile {
281 my ($list_type, $file) = @_;
282 my $list = $lists{$list_type};
284 my $files = $list->{'files'};
287 if ($f{'name'} eq $file) {
289 return (length $f{'content'}, $f{'content'});
291 elsif (!exists($f{'type'}) or $f{'type'} ne "d"){
303 sub ftp_contentlist {
304 my $listname = $_[0];
305 my $list = $lists{$listname};
306 return ftp_createcontent($list);