Debian Codegraph @

tests/t/lib/ProFTPD/TestSuite/FTP.pm

raw
1 package ProFTPD::TestSuite::FTP;
2
3 use strict;
4
5 use Carp;
6 use Net::INET6Glue::FTP;
7 use Net::FTP;
8 use POSIX qw(:sys_wait_h);
9
10 my $conn_ex;
11
12 sub new {
13 my $class = shift;
14 my ($addr, $port, $use_port, $conn_timeout, $cmd_timeout) = @_;
15 $use_port = 0 unless defined($use_port);
16 $conn_timeout = 2 unless defined($conn_timeout);
17
18 my $ftp;
19
20 my $now = time();
21
22 # Creating a Net::FTP object involves attempting to connect to the given
23 # address/port. So handle the test cases where the server process may
24 # not yet be completely up, retry this connect, once a second, up to the
25 # given timeout.
26
27 my %opts = (
28 Port => $port,
29 );
30
31 if ($use_port) {
32 $opts{Passive} = 0;
33
34 } else {
35 $opts{Passive} = 1;
36 }
37
38 if ($ENV{TEST_VERBOSE}) {
39 $opts{Debug} = 10;
40 }
41
42 if (defined($conn_timeout)) {
43 $opts{Timeout} = $conn_timeout;
44 }
45
46 if (defined($cmd_timeout)) {
47 $opts{Timeout} = $cmd_timeout;
48 }
49
50 # Newer versions of libnet changed where/how timeouts are implemented
51 # in the base classes used by Net::FTP. Make sure we provide the necessary
52 # timeouts that WE want. Silly classes.
53 if ($Net::FTP::VERSION >= 3) {
54 my $callback_timeout = 3;
55 $callback_timeout = $cmd_timeout if defined($cmd_timeout);
56 $Net::Cmd::timeout = sub { $callback_timeout };
57 }
58
59 while (1) {
60 if (time() - $now > $conn_timeout) {
61 croak("Unable to connect to $addr:$port: Timed out after $conn_timeout secs");
62 }
63
64 $ftp = Net::FTP->new($addr, %opts);
65 if ($ftp) {
66 last;
67 }
68
69 $conn_ex = $@;
70 chomp($conn_ex);
71 sleep(1);
72 }
73
74 # Naughtily invade the Net::FTP internals; it makes for less confusion
75 # when writing the unit tests.
76 if (exists($ENV{FTP_FIREWALL})) {
77 ${*$ftp}{net_ftp_firewall} = $ENV{FTP_FIREWALL};
78 }
79
80 if (exists($ENV{FTP_FIREWALL_TYPE})) {
81 ${*$ftp}{net_ftp_firewall_type} = $ENV{FTP_FIREWALL_TYPE};
82 }
83
84 my $self = {
85 addr => $addr,
86 ftp => $ftp,
87 port => $port,
88 };
89
90 $conn_ex = undef;
91
92 bless($self, $class);
93 return $self;
94 }
95
96 sub read_response {
97 my $self = shift;
98
99 $self->{ftp}->response();
100
101 my $resp_code = $self->response_code();
102
103 if (wantarray()) {
104 return ($resp_code, $self->response_msg());
105 }
106
107 return $resp_code;
108 }
109
110 sub response_code {
111 my $self = shift;
112 return $self->{ftp}->code;
113 }
114
115 sub response_msg {
116 my $self = shift;
117 my $req_index = shift;
118
119 my $index = 1;
120 if (defined($req_index)) {
121 $index = $req_index;
122 }
123
124 if (defined($self->{mesg})) {
125 my $msg = $self->{mesg};
126 delete($self->{mesg});
127 chomp($msg);
128 return $msg;
129 }
130
131 my @msgs = $self->{ftp}->message;
132 my $nmsgs = scalar(@msgs);
133 if ($nmsgs > 1) {
134 if ($index > ($nmsgs - 1)) {
135 return undef;
136 }
137
138 chomp($msgs[$index]);
139 return $msgs[$index];
140
141 } else {
142 if (defined($req_index)) {
143 if ($index > 0) {
144 return undef;
145 }
146 }
147 }
148
149 if (defined($msgs[0])) {
150 chomp($msgs[0]);
151 }
152
153 return $msgs[0];
154 }
155
156 sub response_msgs {
157 my $self = shift;
158
159 my @msgs = $self->{ftp}->message;
160 my $msgs = [];
161 foreach my $msg (@msgs) {
162 chomp($msg);
163 push(@$msgs, $msg);
164 }
165
166 return $msgs;
167 }
168
169 sub response_uniq {
170 my $self = shift;
171
172 my $uniq;
173 if (defined($self->{uniq})) {
174 $uniq = $self->{uniq};
175 delete($self->{uniq});
176
177 } else {
178 $uniq = $self->{ftp}->unique_name();
179 unless ($uniq) {
180 my @msgs = $self->{ftp}->message;
181 if (scalar(@msgs) > 1) {
182 my $tmp = $msgs[0];
183
184 if ($tmp =~ /^FILE:\s+(\S+)$/) {
185 $uniq = $1;
186 }
187 }
188 }
189 }
190
191 if ($uniq) {
192 chomp($uniq);
193 }
194
195 return $uniq;
196 }
197
198 my $login_timeout = 0;
199 sub login_alarm {
200 croak("Login timed out after $login_timeout secs");
201 }
202
203 sub login {
204 my $self = shift;
205 my $user = shift;
206 croak("Missing required user argument") unless defined($user);
207 my $pass = shift;
208 croak("Missing required password argument") unless defined($pass);
209 $login_timeout = shift;
210 $login_timeout = 30 unless defined($login_timeout);
211
212 $SIG{ALRM} = \&login_alarm;
213 alarm($login_timeout);
214
215 # Work around some (strange? broken?) ness in Net::FTP's handling of
216 # the destination server in the login() method for "firewalls"
217 # (i.e. proxying).
218
219 my $ftp = $self->{ftp};
220 my $net_ftp_host = ${*$ftp}{net_ftp_host};
221
222 if (exists($ENV{FTP_FIREWALL})) {
223 ${*$ftp}{net_ftp_host} = $ENV{FTP_FIREWALL};
224 }
225
226 unless ($self->{ftp}->login($user, $pass)) {
227 if (exists($ENV{FTP_FIREWALL})) {
228 ${*$ftp}{net_ftp_host} = $net_ftp_host;
229 }
230
231 alarm(0);
232 $SIG{ALRM} = 'DEFAULT';
233
234 croak("Failed to login to $self->{addr}:$self->{port}: " .
235 $self->{ftp}->code . ' ' . $self->{ftp}->message);
236 }
237
238 alarm(0);
239 $SIG{ALRM} = 'DEFAULT';
240
241 my $msg = $self->response_msg();
242 if (wantarray()) {
243 return ($self->{ftp}->code, $msg);
244
245 } else {
246 return $msg;
247 }
248 }
249
250 sub user {
251 my $self = shift;
252 my $user = shift;
253 $user = '' unless defined($user);
254 my $code;
255
256 $code = $self->{ftp}->quot('USER', $user);
257 unless ($code) {
258 croak("USER command failed: " . $self->{ftp}->code . ' ' .
259 $self->response_msg());
260 }
261
262 if ($code == 4 || $code == 5) {
263 croak("USER command failed: " . $self->{ftp}->code . ' ' .
264 $self->response_msg());
265 }
266
267 my $msg = $self->response_msg();
268 if (wantarray()) {
269 return ($self->{ftp}->code, $msg);
270
271 } else {
272 return $msg;
273 }
274 }
275
276 sub pass {
277 my $self = shift;
278 my $passwd = shift;
279 $passwd = '' unless defined($passwd);
280 my $code;
281
282 $code = $self->{ftp}->quot('PASS', $passwd);
283 unless ($code) {
284 croak("PASS command failed: " . $self->{ftp}->code . ' ' .
285 $self->response_msg());
286 }
287
288 if ($code == 4 || $code == 5) {
289 croak("PASS command failed: " . $self->{ftp}->code . ' ' .
290 $self->response_msg());
291 }
292
293 my $msg = $self->response_msg();
294 if (wantarray()) {
295 return ($self->{ftp}->code, $msg);
296
297 } else {
298 return $msg;
299 }
300 }
301
302 sub pwd {
303 my $self = shift;
304
305 unless ($self->{ftp}->pwd()) {
306 croak("PWD command failed: " . $self->{ftp}->code . ' ' .
307 $self->response_msg());
308 }
309
310 my $msg = $self->response_msg();
311 if (wantarray()) {
312 return ($self->{ftp}->code, $msg);
313
314 } else {
315 return $msg;
316 }
317 }
318
319 sub xpwd {
320 my $self = shift;
321 my $code;
322
323 $code = $self->{ftp}->quot('XPWD');
324 unless ($code) {
325 croak("XPWD command failed: " . $self->{ftp}->code . ' ' .
326 $self->response_msg());
327 }
328
329 if ($code == 4 || $code == 5) {
330 croak("XPWD command failed: " . $self->{ftp}->code . ' ' .
331 $self->response_msg());
332 }
333
334 my $msg = $self->response_msg();
335 if (wantarray()) {
336 return ($self->{ftp}->code, $msg);
337
338 } else {
339 return $msg;
340 }
341 }
342
343 sub cwd {
344 my $self = shift;
345 my $dir = shift;
346
347 unless ($self->{ftp}->cwd($dir)) {
348 croak("CWD command failed: " . $self->{ftp}->code . ' ' .
349 $self->response_msg());
350 }
351
352 my $msg = $self->response_msg();
353 if (wantarray()) {
354 return ($self->{ftp}->code, $msg);
355
356 } else {
357 return $msg;
358 }
359 }
360
361 sub xcwd {
362 my $self = shift;
363 my $dir = shift;
364 my $code;
365
366 $code = $self->{ftp}->quot('XCWD', $dir);
367 unless ($code) {
368 croak("XCWD command failed: " . $self->{ftp}->code . ' ' .
369 $self->response_msg());
370 }
371
372 if ($code == 4 || $code == 5) {
373 croak("XCWD command failed: " . $self->{ftp}->code . ' ' .
374 $self->response_msg());
375 }
376
377 my $msg = $self->response_msg();
378 if (wantarray()) {
379 return ($self->{ftp}->code, $msg);
380
381 } else {
382 return $msg;
383 }
384 }
385
386 sub cdup {
387 my $self = shift;
388 my $dir = shift;
389
390 unless ($self->{ftp}->cdup()) {
391 croak("CDUP command failed: " . $self->{ftp}->code . ' ' .
392 $self->response_msg());
393 }
394
395 my $msg = $self->response_msg();
396 if (wantarray()) {
397 return ($self->{ftp}->code, $msg);
398
399 } else {
400 return $msg;
401 }
402 }
403
404 sub xcup {
405 my $self = shift;
406 my $code;
407
408 $code = $self->{ftp}->quot('XCUP');
409 unless ($code) {
410 croak("XCUP command failed: " . $self->{ftp}->code . ' ' .
411 $self->response_msg());
412 }
413
414 if ($code == 4 || $code == 5) {
415 croak("XCUP command failed: " . $self->{ftp}->code . ' ' .
416 $self->response_msg());
417 }
418
419 my $msg = $self->response_msg();
420 if (wantarray()) {
421 return ($self->{ftp}->code, $msg);
422
423 } else {
424 return $msg;
425 }
426 }
427
428 sub syst {
429 my $self = shift;
430 my $code;
431
432 $code = $self->{ftp}->quot('SYST');
433 unless ($code) {
434 croak("SYST command failed: " . $self->{ftp}->code . ' ' .
435 $self->response_msg());
436 }
437
438 if ($code == 4 || $code == 5) {
439 croak("SYST command failed: " . $self->{ftp}->code . ' ' .
440 $self->response_msg());
441 }
442
443 my $msg = $self->response_msg();
444 if (wantarray()) {
445 return ($self->{ftp}->code, $msg);
446
447 } else {
448 return $msg;
449 }
450 }
451
452 sub mkd {
453 my $self = shift;
454 my $dir = shift;
455
456 unless ($self->{ftp}->mkdir($dir)) {
457 croak("MKD command failed: " . $self->{ftp}->code . ' ' .
458 $self->response_msg());
459 }
460
461 my $msg = $self->response_msg();
462 if (wantarray()) {
463 return ($self->{ftp}->code, $msg);
464
465 } else {
466 return $msg;
467 }
468 }
469
470 sub xmkd {
471 my $self = shift;
472 my $dir = shift;
473 my $code;
474
475 $code = $self->{ftp}->quot('XMKD', $dir);
476 unless ($code) {
477 croak("XMKD command failed: " . $self->{ftp}->code . ' ' .
478 $self->response_msg());
479 }
480
481 if ($code == 4 || $code == 5) {
482 croak("XMKD command failed: " . $self->{ftp}->code . ' ' .
483 $self->response_msg());
484 }
485
486 my $msg = $self->response_msg();
487 if (wantarray()) {
488 return ($self->{ftp}->code, $msg);
489
490 } else {
491 return $msg;
492 }
493 }
494
495 sub rmd {
496 my $self = shift;
497 my $dir = shift;
498
499 unless ($self->{ftp}->rmdir($dir)) {
500 croak("RMD command failed: " . $self->{ftp}->code . ' ' .
501 $self->response_msg());
502 }
503
504 my $msg = $self->response_msg();
505 if (wantarray()) {
506 return ($self->{ftp}->code, $msg);
507
508 } else {
509 return $msg;
510 }
511 }
512
513 sub xrmd {
514 my $self = shift;
515 my $dir = shift;
516 my $code;
517
518 $code = $self->{ftp}->quot('XRMD', $dir);
519 unless ($code) {
520 croak("XRMD command failed: " . $self->{ftp}->code . ' ' .
521 $self->response_msg());
522 }
523
524 if ($code == 4 || $code == 5) {
525 croak("XRMD command failed: " . $self->{ftp}->code . ' ' .
526 $self->response_msg());
527 }
528
529 my $msg = $self->response_msg();
530 if (wantarray()) {
531 return ($self->{ftp}->code, $msg);
532
533 } else {
534 return $msg;
535 }
536 }
537
538 sub dele {
539 my $self = shift;
540 my $path = shift;
541
542 unless ($self->{ftp}->delete($path)) {
543 croak("DELE command failed: " . $self->{ftp}->code . ' ' .
544 $self->response_msg());
545 }
546
547 my $msg = $self->response_msg();
548 if (wantarray()) {
549 return ($self->{ftp}->code, $msg);
550
551 } else {
552 return $msg;
553 }
554 }
555
556 sub type {
557 my $self = shift;
558 my $type = shift;
559
560 if ($type =~ /^ascii$/i) {
561 unless ($self->{ftp}->ascii()) {
562 croak("TYPE command failed: " . $self->{ftp}->code . ' ' .
563 $self->response_msg());
564 }
565
566 } elsif ($type =~ /^binary$/i) {
567 unless ($self->{ftp}->binary()) {
568 croak("TYPE command failed: " . $self->{ftp}->code . ' ' .
569 $self->response_msg());
570 }
571
572 } else {
573 my $code;
574
575 $code = $self->{ftp}->quot('TYPE', $type);
576 unless ($code) {
577 croak("TYPE command failed: " . $self->{ftp}->code . ' ' .
578 $self->response_msg());
579 }
580
581 if ($code == 4 || $code == 5) {
582 croak("TYPE command failed: " . $self->{ftp}->code . ' ' .
583 $self->response_msg());
584 }
585 }
586
587 my $msg = $self->response_msg();
588 if (wantarray()) {
589 return ($self->{ftp}->code, $msg);
590
591 } else {
592 return $msg;
593 }
594 }
595
596 sub mdtm {
597 my $self = shift;
598 my $path = shift;
599
600 unless ($self->{ftp}->mdtm($path)) {
601 croak("MDTM command failed: " . $self->{ftp}->code . ' ' .
602 $self->response_msg());
603 }
604
605 my $msg = $self->response_msg();
606 if (wantarray()) {
607 return ($self->{ftp}->code, $msg);
608
609 } else {
610 return $msg;
611 }
612 }
613
614 sub size {
615 my $self = shift;
616 my $path = shift;
617
618 unless ($self->{ftp}->size($path)) {
619 croak("SIZE command failed: " . $self->{ftp}->code . ' ' .
620 $self->response_msg());
621 }
622
623 my $msg = $self->response_msg();
624 if (wantarray()) {
625 return ($self->{ftp}->code, $msg);
626
627 } else {
628 return $msg;
629 }
630 }
631
632 sub pasv {
633 my $self = shift;
634
635 unless ($self->{ftp}->pasv()) {
636 croak("PASV command failed: " . $self->{ftp}->code . ' ' .
637 $self->response_msg());
638 }
639
640 # Naughtily invade the Net::FTP internals; it makes for less confusion
641 # when writing the unit tests.
642 my $ftp = $self->{ftp};
643 ${*$ftp}{net_ftp_passive} = 1;
644
645 my $msg = $self->response_msg();
646 if (wantarray()) {
647 return ($self->{ftp}->code, $msg);
648
649 } else {
650 return $msg;
651 }
652 }
653
654 sub epsv {
655 my $self = shift;
656 my $proto = shift;
657 $proto = '' unless defined($proto);
658 my $code;
659
660 $code = $self->{ftp}->quot('EPSV', $proto);
661 unless ($code) {
662 croak("EPSV command failed: " . $self->{ftp}->code . ' ' .
663 $self->response_msg());
664 }
665
666 if ($code == 4 || $code == 5) {
667 croak("EPSV command failed: " . $self->{ftp}->code . ' ' .
668 $self->response_msg());
669 }
670
671 # Naughtily invade the Net::FTP internals; it makes for less confusion
672 # when writing the unit tests.
673 my $ftp = $self->{ftp};
674 ${*$ftp}{net_ftp_passive} = 1;
675
676 my $msg = $self->response_msg();
677 if (wantarray()) {
678 return ($self->{ftp}->code, $msg);
679
680 } else {
681 return $msg;
682 }
683 }
684
685 sub port {
686 my $self = shift;
687 my $port = shift;
688
689 unless ($self->{ftp}->port($port)) {
690 croak("PORT command failed: " . $self->{ftp}->code . ' ' .
691 $self->response_msg());
692 }
693
694 # Naughtily invade the Net::FTP internals; it makes for less confusion
695 # when writing the unit tests.
696 my $ftp = $self->{ftp};
697
698 if ($port) {
699 # Determine the local port from the given argument.
700
701 my $numbers = [split(',', $port)];
702 my $local_port = ($numbers->[4] * 256) + $numbers->[5];
703
704 # If the caller provided an explicit PORT argument, then we need to
705 # open the listening socket ourselves. Net::FTP is braindead that way.
706 #
707 # The code below is copied from Net::FTP::port().
708
709 ${*$ftp}{net_ftp_listen} ||= IO::Socket::INET->new(
710 Listen => 5,
711 Proto => 'tcp',
712 Timeout => $ftp->timeout,
713 LocalAddr => $ftp->sockhost,
714 LocalPort => $local_port,
715 );
716
717 ${*$ftp}{net_ftp_intern_port} = 1;
718 }
719
720 delete(${*$ftp}{net_ftp_passive});
721
722 my $msg = $self->response_msg();
723 if (wantarray()) {
724 return ($self->{ftp}->code, $msg);
725
726 } else {
727 return $msg;
728 }
729 }
730
731 sub eprt {
732 my $self = shift;
733 my $port = shift;
734 $port = '' unless defined($port);
735 my $code;
736
737 $code = $self->{ftp}->quot('EPRT', $port);
738 unless ($code) {
739 croak("EPRT command failed: " . $self->{ftp}->code . ' ' .
740 $self->response_msg());
741 }
742
743 if ($code == 4 || $code == 5) {
744 croak("EPRT command failed: " . $self->{ftp}->code . ' ' .
745 $self->response_msg());
746 }
747
748 # Naughtily invade the Net::FTP internals; it makes for less confusion
749 # when writing the unit tests.
750 my $ftp = $self->{ftp};
751 delete(${*$ftp}{net_ftp_passive});
752
753 my $msg = $self->response_msg();
754 if (wantarray()) {
755 return ($self->{ftp}->code, $msg);
756
757 } else {
758 return $msg;
759 }
760 }
761
762 sub mode {
763 my $self = shift;
764 my $mode = shift;
765
766 if ($mode =~ /^stream$/i) {
767 my $code;
768
769 $code = $self->{ftp}->quot('MODE', 'S');
770 unless ($code) {
771 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
772 $self->response_msg());
773 }
774
775 if ($code == 4 || $code == 5) {
776 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
777 $self->response_msg());
778 }
779
780 } elsif ($mode =~ /^block$/i) {
781 my $code;
782
783 $code = $self->{ftp}->quot('MODE', 'B');
784 unless ($code) {
785 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
786 $self->response_msg());
787 }
788
789 if ($code == 4 || $code == 5) {
790 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
791 $self->response_msg());
792 }
793
794 } elsif ($mode =~ /^compress(ed)?$/i) {
795 my $code;
796
797 $code = $self->{ftp}->quot('MODE', 'C');
798 unless ($code) {
799 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
800 $self->response_msg());
801 }
802
803 if ($code == 4 || $code == 5) {
804 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
805 $self->response_msg());
806 }
807
808 } else {
809 my $code;
810
811 $code = $self->{ftp}->quot('MODE', $mode);
812 unless ($code) {
813 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
814 $self->response_msg());
815 }
816
817 if ($code == 4 || $code == 5) {
818 croak("MODE command failed: " . $self->{ftp}->code . ' ' .
819 $self->response_msg());
820 }
821 }
822
823 my $msg = $self->response_msg();
824 if (wantarray()) {
825 return ($self->{ftp}->code, $msg);
826
827 } else {
828 return $msg;
829 }
830 }
831
832 sub stru {
833 my $self = shift;
834 my $stru = shift;
835
836 if ($stru =~ /^file$/i) {
837 my $code;
838
839 $code = $self->{ftp}->quot('STRU', 'F');
840 unless ($code) {
841 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
842 $self->response_msg());
843 }
844
845 if ($code == 4 || $code == 5) {
846 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
847 $self->response_msg());
848 }
849
850 } elsif ($stru =~ /^record$/i) {
851 my $code;
852
853 $code = $self->{ftp}->quot('STRU', 'R');
854 unless ($code) {
855 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
856 $self->response_msg());
857 }
858
859 if ($code == 4 || $code == 5) {
860 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
861 $self->response_msg());
862 }
863
864 } elsif ($stru =~ /^page$/i) {
865 my $code;
866
867 $code = $self->{ftp}->quot('STRU', 'P');
868 unless ($code) {
869 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
870 $self->response_msg());
871 }
872
873 if ($code == 4 || $code == 5) {
874 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
875 $self->response_msg());
876 }
877
878 } else {
879 my $code;
880
881 $code = $self->{ftp}->quot('STRU', $stru);
882 unless ($code) {
883 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
884 $self->response_msg());
885 }
886
887 if ($code == 4 || $code == 5) {
888 croak("STRU command failed: " . $self->{ftp}->code . ' ' .
889 $self->response_msg());
890 }
891 }
892
893 my $msg = $self->response_msg();
894 if (wantarray()) {
895 return ($self->{ftp}->code, $msg);
896
897 } else {
898 return $msg;
899 }
900 }
901
902 sub allo {
903 my $self = shift;
904 my $size = shift;
905
906 # XXX Net::FTP has a bug with its alloc() method, where a 202 response
907 # code is incorrectly handled as an error.
908 my $code = 0;
909
910 $self->{ftp}->alloc($size);
911
912 if ($self->{ftp}->code =~ /^(\d)/) {
913 $code = $1;
914 }
915
916 if ($code == 4 || $code == 5) {
917 croak("ALLO command failed: " . $self->{ftp}->code . ' ' .
918 $self->response_msg());
919 }
920
921 my $msg = $self->response_msg();
922 if (wantarray()) {
923 return ($self->{ftp}->code, $msg);
924
925 } else {
926 return $msg;
927 }
928 }
929
930 sub noop {
931 my $self = shift;
932 my $code;
933
934 $code = $self->{ftp}->quot('NOOP');
935 unless ($code) {
936 croak("NOOP command failed: " . $self->{ftp}->code . ' ' .
937 $self->response_msg());
938 }
939
940 if ($code == 4 || $code == 5) {
941 croak("NOOP command failed: " . $self->{ftp}->code . ' ' .
942 $self->response_msg());
943 }
944
945 my $msg = $self->response_msg();
946 if (wantarray()) {
947 return ($self->{ftp}->code, $msg);
948
949 } else {
950 return $msg;
951 }
952 }
953
954 sub rnfr {
955 my $self = shift;
956 my $path = shift;
957 my $code;
958
959 $code = $self->{ftp}->quot('RNFR', $path);
960 unless ($code) {
961 croak("RNFR command failed: " . $self->{ftp}->code . ' ' .
962 $self->response_msg());
963 }
964
965 if ($code == 4 || $code == 5) {
966 croak("RNFR command failed: " . $self->{ftp}->code . ' ' .
967 $self->response_msg());
968 }
969
970 my $msg = $self->response_msg();
971 if (wantarray()) {
972 return ($self->{ftp}->code, $msg);
973
974 } else {
975 return $msg;
976 }
977 }
978
979 sub rnto {
980 my $self = shift;
981 my $path = shift;
982 my $code;
983
984 $code = $self->{ftp}->quot('RNTO', $path);
985 unless ($code) {
986 croak("RNTO command failed: " . $self->{ftp}->code . ' ' .
987 $self->response_msg());
988 }
989
990 if ($code == 4 || $code == 5) {
991 croak("RNTO command failed: " . $self->{ftp}->code . ' ' .
992 $self->response_msg());
993 }
994
995 my $msg = $self->response_msg();
996 if (wantarray()) {
997 return ($self->{ftp}->code, $msg);
998
999 } else {
1000 return $msg;
1001 }
1002 }
1003
1004 sub quit {
1005 my $self = shift;
1006
1007 unless ($self->{ftp}->quit()) {
1008 croak("QUIT command failed: " . $self->{ftp}->code . ' ' .
1009 $self->response_msg());
1010 }
1011
1012 my $msg = $self->response_msg();
1013 if (wantarray()) {
1014 return ($self->{ftp}->code, $msg);
1015
1016 } else {
1017 return $msg;
1018 }
1019 }
1020
1021 sub rang {
1022 my $self = shift;
1023 my $range_start = shift;
1024 croak("Missing range start") unless defined($range_start);
1025 my $range_end = shift;
1026 croak("Missing range end") unless defined($range_end);
1027 my $code;
1028
1029 $code = $self->{ftp}->quot('RANG', $range_start, $range_end);
1030 unless ($code) {
1031 croak("RANG command failed: " . $self->{ftp}->code . ' ' .
1032 $self->response_msg());
1033 }
1034
1035 if ($code == 4 || $code == 5) {
1036 croak("RANG command failed: " . $self->{ftp}->code . ' ' .
1037 $self->response_msg());
1038 }
1039
1040 my $msg = $self->response_msg();
1041 if (wantarray()) {
1042 return ($self->{ftp}->code, $msg);
1043 }
1044
1045 return $msg;
1046 }
1047
1048 sub rest {
1049 my $self = shift;
1050 my $offset = shift;
1051 $offset = '' unless defined($offset);
1052 my $code;
1053
1054 $code = $self->{ftp}->quot('REST', $offset);
1055 unless ($code) {
1056 croak("REST command failed: " . $self->{ftp}->code . ' ' .
1057 $self->response_msg());
1058 }
1059
1060 if ($code == 4 || $code == 5) {
1061 croak("REST command failed: " . $self->{ftp}->code . ' ' .
1062 $self->response_msg());
1063 }
1064
1065 my $msg = $self->response_msg();
1066 if (wantarray()) {
1067 return ($self->{ftp}->code, $msg);
1068
1069 } else {
1070 return $msg;
1071 }
1072 }
1073
1074 sub nlst {
1075 my $self = shift;
1076 my $path = shift;
1077 $path = '' unless defined($path);
1078
1079 my $res;
1080
1081 $res = $self->{ftp}->nlst($path);
1082 unless ($res) {
1083 croak("NLST command failed: " . $self->{ftp}->code . ' ' .
1084 $self->response_msg());
1085 }
1086
1087 if (ref($res)) {
1088 my $buf;
1089 while ($res->read($buf, 8192) > 0) {
1090 }
1091
1092 $res->close();
1093 }
1094
1095 my $msg = $self->response_msg();
1096 if (wantarray()) {
1097 return ($self->{ftp}->code, $msg);
1098
1099 } else {
1100 return $msg;
1101 }
1102 }
1103
1104 sub nlst_raw {
1105 my $self = shift;
1106 my $path = shift;
1107 $path = '' unless defined($path);
1108
1109 return $self->{ftp}->nlst($path);
1110 }
1111
1112 sub list {
1113 my $self = shift;
1114 my $path = shift;
1115 $path = '' unless defined($path);
1116
1117 my $res;
1118
1119 $res = $self->{ftp}->list($path);
1120 unless ($res) {
1121 croak("LIST command failed: " . $self->{ftp}->code . ' ' .
1122 $self->response_msg());
1123 }
1124
1125 if (ref($res)) {
1126 my $buf;
1127 while ($res->read($buf, 8192) > 0) {
1128 }
1129
1130 $res->close();
1131 }
1132
1133 # XXX Work around bug in Net::FTP which fails to handle the case where,
1134 # for data transfers, a 150 response code may be sent (to open the data
1135 # connection), followed by an error response code.
1136 my $code = 0;
1137
1138 if ($self->{ftp}->code =~ /^(\d)/) {
1139 $code = $1;
1140 }
1141
1142 if ($code == 4 || $code == 5) {
1143 my $msg = $self->response_msg();
1144 $self->{mesg} = $msg;
1145
1146 croak("LIST command failed: " . $self->{ftp}->code . ' ' . $msg);
1147 }
1148
1149 my $msg = $self->response_msg();
1150 if (wantarray()) {
1151 return ($self->{ftp}->code, $msg);
1152
1153 } else {
1154 return $msg;
1155 }
1156 }
1157
1158 sub list_raw {
1159 my $self = shift;
1160 my $path = shift;
1161 $path = '' unless defined($path);
1162
1163 return $self->{ftp}->list($path);
1164 }
1165
1166 sub retr {
1167 my $self = shift;
1168 my $src_path = shift;
1169 $src_path = '' unless defined($src_path);
1170 my $dst_path = shift;
1171 $dst_path = '/dev/null' unless defined($dst_path);
1172
1173 my $res;
1174
1175 $res = $self->{ftp}->get($src_path, $dst_path);
1176 unless ($res) {
1177 croak("RETR command failed: " . $self->{ftp}->code . ' ' .
1178 $self->response_msg());
1179 }
1180
1181 if (ref($res)) {
1182 my $buf;
1183 while ($res->read($buf, 8192) > 0) {
1184 }
1185
1186 $res->close();
1187 }
1188
1189 # XXX Work around bug in Net::FTP which fails to handle the case where,
1190 # for data transfers, a 150 response code may be sent (to open the data
1191 # connection), followed by an error response code.
1192 my $code = 0;
1193
1194 if ($self->{ftp}->code =~ /^(\d)/) {
1195 $code = $1;
1196 }
1197
1198 if ($code == 4 || $code == 5) {
1199 my $msg = $self->response_msg();
1200 $self->{mesg} = $msg;
1201
1202 croak("RETR command failed: " . $self->{ftp}->code . ' ' . $msg);
1203 }
1204
1205 my $msg = $self->response_msg();
1206 if (wantarray()) {
1207 return ($self->{ftp}->code, $msg);
1208
1209 } else {
1210 return $msg;
1211 }
1212 }
1213
1214 sub retr_raw {
1215 my $self = shift;
1216 my $path = shift;
1217 $path = '' unless defined($path);
1218
1219 return $self->{ftp}->retr($path);
1220 }
1221
1222 sub stor {
1223 my $self = shift;
1224 my $src_path = shift;
1225 $src_path = '' unless defined($src_path);
1226 my $dst_path = shift;
1227 $dst_path = '/dev/null' unless defined($dst_path);
1228
1229 my $res;
1230
1231 $res = $self->{ftp}->put($src_path, $dst_path);
1232 unless ($res) {
1233 croak("STOR command failed: " . $self->{ftp}->code . ' ' .
1234 $self->response_msg());
1235 }
1236
1237 # XXX Work around bug in Net::FTP which fails to handle the case where,
1238 # for data transfers, a 150 response code may be sent (to open the data
1239 # connection), followed by an error response code.
1240 my $code = 0;
1241
1242 if ($self->{ftp}->code =~ /^(\d)/) {
1243 $code = $1;
1244 }
1245
1246 if ($code == 4 || $code == 5) {
1247 my $msg = $self->response_msg();
1248 $self->{mesg} = $msg;
1249
1250 croak("STOR command failed: " . $self->{ftp}->code . ' ' . $msg);
1251 }
1252
1253 my $msg = $self->response_msg();
1254 if (wantarray()) {
1255 return ($self->{ftp}->code, $msg);
1256
1257 } else {
1258 return $msg;
1259 }
1260 }
1261
1262 sub stor_raw {
1263 my $self = shift;
1264 my $path = shift;
1265 $path = '' unless defined($path);
1266
1267 return $self->{ftp}->stor($path);
1268 }
1269
1270 sub stou {
1271 my $self = shift;
1272 my $src_path = shift;
1273 $src_path = '' unless defined($src_path);
1274 my $dst_path = shift;
1275 $dst_path = '' unless defined($dst_path);
1276
1277 my $res;
1278
1279 $res = $self->{ftp}->put_unique($src_path, $dst_path);
1280 unless ($res) {
1281 croak("STOU command failed: " . $self->{ftp}->code . ' ' .
1282 $self->response_msg());
1283 }
1284
1285 $self->{uniq} = $res;
1286
1287 # XXX Work around bug in Net::FTP which fails to handle the case where,
1288 # for data transfers, a 150 response code may be sent (to open the data
1289 # connection), followed by an error response code.
1290 my $code = 0;
1291
1292 if ($self->{ftp}->code =~ /^(\d)/) {
1293 $code = $1;
1294 }
1295
1296 if ($code == 4 || $code == 5) {
1297 my $msg = $self->response_msg();
1298 $self->{mesg} = $msg;
1299
1300 croak("STOU command failed: " . $self->{ftp}->code . ' ' . $msg);
1301 }
1302
1303 my $msg = $self->response_msg();
1304 if (wantarray()) {
1305 return ($self->{ftp}->code, $msg);
1306
1307 } else {
1308 return $msg;
1309 }
1310 }
1311
1312 sub stou_raw {
1313 my $self = shift;
1314 my $path = shift;
1315 $path = '' unless defined($path);
1316
1317 return $self->{ftp}->stou($path);
1318 }
1319
1320 sub appe {
1321 my $self = shift;
1322 my $src_path = shift;
1323 $src_path = '' unless defined($src_path);
1324 my $dst_path = shift;
1325 $dst_path = '/dev/null' unless defined($dst_path);
1326
1327 my $res;
1328
1329 $res = $self->{ftp}->append($src_path, $dst_path);
1330 unless ($res) {
1331 croak("APPE command failed: " . $self->{ftp}->code . ' ' .
1332 $self->response_msg());
1333 }
1334
1335 # XXX Work around bug in Net::FTP which fails to handle the case where,
1336 # for data transfers, a 150 response code may be sent (to open the data
1337 # connection), followed by an error response code.
1338 my $code = 0;
1339
1340 if ($self->{ftp}->code =~ /^(\d)/) {
1341 $code = $1;
1342 }
1343
1344 if ($code == 4 || $code == 5) {
1345 my $msg = $self->response_msg();
1346 $self->{mesg} = $msg;
1347
1348 croak("APPE command failed: " . $self->{ftp}->code . ' ' . $msg);
1349 }
1350
1351 my $msg = $self->response_msg();
1352 if (wantarray()) {
1353 return ($self->{ftp}->code, $msg);
1354
1355 } else {
1356 return $msg;
1357 }
1358 }
1359
1360 sub appe_raw {
1361 my $self = shift;
1362 my $path = shift;
1363 $path = '' unless defined($path);
1364
1365 return $self->{ftp}->appe($path);
1366 }
1367
1368 sub feat {
1369 my $self = shift;
1370 my $code;
1371
1372 $code = $self->{ftp}->quot('FEAT');
1373 unless ($code) {
1374 croak("FEAT command failed: " . $self->{ftp}->code . ' ' .
1375 $self->response_msg());
1376 }
1377
1378 if ($code == 4 || $code == 5) {
1379 croak("FEAT command failed: " . $self->{ftp}->code . ' ' .
1380 $self->response_msg());
1381 }
1382
1383 my $msg = $self->response_msg();
1384 if (wantarray()) {
1385 return ($self->{ftp}->code, $msg);
1386
1387 } else {
1388 return $msg;
1389 }
1390 }
1391
1392 sub help {
1393 my $self = shift;
1394 my $code;
1395
1396 $code = $self->{ftp}->quot('HELP');
1397 unless ($code) {
1398 croak("HELP command failed: " . $self->{ftp}->code . ' ' .
1399 $self->response_msg());
1400 }
1401
1402 if ($code == 4 || $code == 5) {
1403 croak("HELP command failed: " . $self->{ftp}->code . ' ' .
1404 $self->response_msg());
1405 }
1406
1407 my $msg = $self->response_msg();
1408 if (wantarray()) {
1409 return ($self->{ftp}->code, $msg);
1410
1411 } else {
1412 return $msg;
1413 }
1414 }
1415
1416 sub site {
1417 my $self = shift;
1418 my $cmd = shift;
1419 $cmd = '' unless defined($cmd);
1420 my $code;
1421
1422 $code = $self->{ftp}->quot('SITE', $cmd, @_);
1423 unless ($code) {
1424 croak("SITE command failed: " . $self->{ftp}->code . ' ' .
1425 $self->response_msg());
1426 }
1427
1428 if ($code == 4 || $code == 5) {
1429 croak("SITE command failed: " . $self->{ftp}->code . ' ' .
1430 $self->response_msg());
1431 }
1432
1433 my $msg = $self->response_msg();
1434 if (wantarray()) {
1435 return ($self->{ftp}->code, $msg);
1436
1437 } else {
1438 return $msg;
1439 }
1440 }
1441
1442 sub quote {
1443 my $self = shift;
1444 my $cmd = shift;
1445 $cmd = '' unless defined($cmd);
1446 my $code;
1447
1448 $code = $self->{ftp}->quot($cmd, @_);
1449 unless ($code) {
1450 croak("Raw command '$cmd' failed: " . $self->{ftp}->code . ' ' .
1451 $self->response_msg());
1452 }
1453
1454 # Per RFC 959, the ABOR command expects either one or two responses. If
1455 # there is a data transfer in progress, the first response is for the
1456 # aborted transfer, the second response is for the ABOR command itself.
1457 #
1458 # Thus we have to call response() again, for ABOR, to handle this properly.
1459 if ($cmd =~ /^abor$/i) {
1460 $self->{ftp}->response() if defined ${*{$self->{ftp}}}{'net_ftp_dataconn'};
1461 }
1462
1463 if ($code == 4 || $code == 5) {
1464 croak("Raw command '$cmd' failed: " . $self->{ftp}->code . ' ' .
1465 $self->response_msg());
1466 }
1467
1468 my $msg = $self->response_msg();
1469 if (wantarray()) {
1470 return ($self->{ftp}->code, $msg);
1471 }
1472
1473 return $msg;
1474 }
1475
1476 sub quote_raw {
1477 my $self = shift;
1478 my $cmd = shift;
1479 $cmd = '' unless defined($cmd);
1480 my $code;
1481
1482 # Net::FTP::quot() calls uc() on the command; we want to send the "raw"
1483 # command here.
1484 $self->{ftp}->command($cmd, @_);
1485 $code = $self->{ftp}->response();
1486 unless ($code) {
1487 croak("Raw command '$cmd' failed: " . $self->{ftp}->code . ' ' .
1488 $self->response_msg());
1489 }
1490
1491 if ($code == 4 || $code == 5) {
1492 croak("Raw command '$cmd' failed: " . $self->{ftp}->code . ' ' .
1493 $self->response_msg());
1494 }
1495
1496 my $msg = $self->response_msg();
1497 if (wantarray()) {
1498 return ($self->{ftp}->code, $msg);
1499
1500 } else {
1501 return $msg;
1502 }
1503 }
1504
1505 sub mlsd {
1506 my $self = shift;
1507 my $path = shift;
1508 $path = '' unless defined($path);
1509
1510 my $res;
1511
1512 $res = $self->{ftp}->_data_cmd('MLSD', $path);
1513 unless ($res) {
1514 croak("MLSD command failed: " . $self->{ftp}->code . ' ' .
1515 $self->response_msg());
1516 }
1517
1518 if (ref($res)) {
1519 my $buf;
1520 while ($res->read($buf, 8192) > 0) {
1521 }
1522
1523 $res->close();
1524 }
1525
1526 # XXX Work around bug in Net::FTP which fails to handle the case where,
1527 # for data transfers, a 150 response code may be sent (to open the data
1528 # connection), followed by an error response code.
1529 my $code = 0;
1530
1531 if ($self->{ftp}->code =~ /^(\d)/) {
1532 $code = $1;
1533 }
1534
1535 if ($code == 4 || $code == 5) {
1536 my $msg = $self->response_msg();
1537 $self->{mesg} = $msg;
1538
1539 croak("MLSD command failed: " . $self->{ftp}->code . ' ' . $msg);
1540 }
1541
1542 my $msg = $self->response_msg();
1543 if (wantarray()) {
1544 return ($self->{ftp}->code, $msg);
1545
1546 } else {
1547 return $msg;
1548 }
1549 }
1550
1551 sub mlsd_raw {
1552 my $self = shift;
1553 my $path = shift;
1554 $path = '' unless defined($path);
1555 my $conn;
1556
1557 $conn = $self->{ftp}->_data_cmd('MLSD', $path);
1558 return $conn;
1559 }
1560
1561 sub mlst {
1562 my $self = shift;
1563 my $path = shift;
1564 $path = '' unless defined($path);
1565 my $code;
1566
1567 $code = $self->{ftp}->quot('MLST', $path);
1568 unless ($code) {
1569 croak("MLST command failed: " . $self->{ftp}->code . ' ' .
1570 $self->response_msg());
1571 }
1572
1573 if ($code == 4 || $code == 5) {
1574 croak("MLST command failed: " . $self->{ftp}->code . ' ' .
1575 $self->response_msg());
1576 }
1577
1578 my $msg = $self->response_msg();
1579 if (wantarray()) {
1580 return ($self->{ftp}->code, $msg);
1581
1582 } else {
1583 return $msg;
1584 }
1585 }
1586
1587 sub mff {
1588 my $self = shift;
1589 my $facts = shift;
1590 $facts = '' unless defined($facts);
1591 my $path = shift;
1592 $path = '' unless defined($path);
1593 my $code;
1594
1595 $code = $self->{ftp}->quot('MFF', $facts, $path);
1596 unless ($code) {
1597 croak("MFF command failed: " . $self->{ftp}->code . ' ' .
1598 $self->response_msg());
1599 }
1600
1601 if ($code == 4 || $code == 5) {
1602 croak("MFF command failed: " . $self->{ftp}->code . ' ' .
1603 $self->response_msg());
1604 }
1605
1606 my $msg = $self->response_msg();
1607 if (wantarray()) {
1608 return ($self->{ftp}->code, $msg);
1609
1610 } else {
1611 return $msg;
1612 }
1613 }
1614
1615 sub mfmt {
1616 my $self = shift;
1617 my $timestamp = shift;
1618 $timestamp = '' unless defined($timestamp);
1619 my $path = shift;
1620 $path = '' unless defined($path);
1621 my $code;
1622
1623 $code = $self->{ftp}->quot('MFMT', $timestamp, $path);
1624 unless ($code) {
1625 croak("MFMT command failed: " . $self->{ftp}->code . ' ' .
1626 $self->response_msg());
1627 }
1628
1629 if ($code == 4 || $code == 5) {
1630 croak("MFMT command failed: " . $self->{ftp}->code . ' ' .
1631 $self->response_msg());
1632 }
1633
1634 my $msg = $self->response_msg();
1635 if (wantarray()) {
1636 return ($self->{ftp}->code, $msg);
1637
1638 } else {
1639 return $msg;
1640 }
1641 }
1642
1643 sub lang {
1644 my $self = shift;
1645 my $lang = shift;
1646 $lang = '' unless defined($lang);
1647 my $code;
1648
1649 $code = $self->{ftp}->quot('LANG', $lang);
1650 unless ($code) {
1651 croak("LANG command failed: " . $self->{ftp}->code . ' ' .
1652 $self->response_msg());
1653 }
1654
1655 if ($code == 4 || $code == 5) {
1656 croak("LANG command failed: " . $self->{ftp}->code . ' ' .
1657 $self->response_msg());
1658 }
1659
1660 my $msg = $self->response_msg();
1661 if (wantarray()) {
1662 return ($self->{ftp}->code, $msg);
1663
1664 } else {
1665 return $msg;
1666 }
1667 }
1668
1669 sub opts {
1670 my $self = shift;
1671 my $cmd = shift;
1672 $cmd = '' unless defined($cmd);
1673 my $code;
1674
1675 $code = $self->{ftp}->quot('OPTS', $cmd, @_);
1676 unless ($code) {
1677 croak("OPTS command failed: " . $self->{ftp}->code . ' ' .
1678 $self->response_msg());
1679 }
1680
1681 if ($code == 4 || $code == 5) {
1682 croak("OPTS command failed: " . $self->{ftp}->code . ' ' .
1683 $self->response_msg());
1684 }
1685
1686 my $msg = $self->response_msg();
1687 if (wantarray()) {
1688 return ($self->{ftp}->code, $msg);
1689
1690 } else {
1691 return $msg;
1692 }
1693 }
1694
1695 sub get_connect_exception {
1696 return $conn_ex;
1697 }
1698
1699 sub stat {
1700 my $self = shift;
1701 my $path = shift;
1702 $path = '' unless defined($path);
1703 my $code;
1704
1705 $code = $self->{ftp}->quot('STAT', $path);
1706 unless ($code) {
1707 croak("STAT command failed: " . $self->{ftp}->code . ' ' .
1708 $self->response_msg());
1709 }
1710
1711 if ($code == 4 || $code == 5) {
1712 croak("STAT command failed: " . $self->{ftp}->code . ' ' .
1713 $self->response_msg());
1714 }
1715
1716 my $msg = $self->response_msg();
1717 if (wantarray()) {
1718 return ($self->{ftp}->code, $msg);
1719
1720 } else {
1721 return $msg;
1722 }
1723 }
1724
1725 # From the FTP HOST command RFC 7151
1726 sub host {
1727 my $self = shift;
1728 my $host = shift;
1729 $host = '' unless defined($host);
1730 my $code;
1731
1732 $code = $self->{ftp}->quot('HOST', $host);
1733 unless ($code) {
1734 croak("HOST command failed: " . $self->{ftp}->code . ' ' .
1735 $self->response_msg());
1736 }
1737
1738 if ($code == 4 || $code == 5) {
1739 croak("HOST command failed: " . $self->{ftp}->code . ' ' .
1740 $self->response_msg());
1741 }
1742
1743 my $msg = $self->response_msg();
1744 if (wantarray()) {
1745 return ($self->{ftp}->code, $msg);
1746
1747 } else {
1748 return $msg;
1749 }
1750 }
1751
1752 sub clnt {
1753 my $self = shift;
1754 my $info = shift;
1755 $info = 'ProFTPD::TestSuite::FTP' unless defined($info);
1756 my $code;
1757
1758 $code = $self->{ftp}->quot('CLNT', $info);
1759 unless ($code) {
1760 croak("CLNT command failed: " . $self->{ftp}->code . ' ' .
1761 $self->response_msg());
1762 }
1763
1764 if ($code == 4 || $code == 5) {
1765 croak("CLNT command failed: " . $self->{ftp}->code . ' ' .
1766 $self->response_msg());
1767 }
1768
1769 my $msg = $self->response_msg();
1770 if (wantarray()) {
1771 return ($self->{ftp}->code, $msg);
1772
1773 } else {
1774 return $msg;
1775 }
1776 }
1777
1778 sub csid {
1779 my $self = shift;
1780 my $info = shift;
1781 $info = 'ProFTPD::TestSuite::FTP' unless defined($info);
1782 my $code;
1783
1784 $code = $self->{ftp}->quot('CSID', $info);
1785 unless ($code) {
1786 croak("CSID command failed: " . $self->{ftp}->code . ' ' .
1787 $self->response_msg());
1788 }
1789
1790 if ($code == 4 || $code == 5) {
1791 croak("CSID command failed: " . $self->{ftp}->code . ' ' .
1792 $self->response_msg());
1793 }
1794
1795 my $msg = $self->response_msg();
1796 if (wantarray()) {
1797 return ($self->{ftp}->code, $msg);
1798
1799 } else {
1800 return $msg;
1801 }
1802 }
1803
1804 sub abort {
1805 my $self = shift;
1806
1807 unless ($self->{ftp}->abort()) {
1808 croak("ABOR command failed: " . $self->{ftp}->code . ' ' .
1809 $self->response_msg());
1810 }
1811
1812 my $msg = $self->response_msg();
1813 if (wantarray()) {
1814 return ($self->{ftp}->code, $msg);
1815
1816 } else {
1817 return $msg;
1818 }
1819 }
1820
1821 1;