This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate CPAN release of version.pm 0.9905
[perl5.git] / cpan / libnet / t / ftp.t
CommitLineData
406c51ee
JH
1#!./perl -w
2
302cc833
GB
3BEGIN {
4 unless (-d 'blib') {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
1a8dcddb 8 if (!eval "require Socket") {
8723f121 9 print "1..0 # Skip: no Socket module\n"; exit 0;
1a8dcddb 10 }
8b14f033 11 if (ord('A') == 193 && !eval "require Convert::EBCDIC") {
8723f121 12 print "1..0 # Skip: EBCDIC but no Convert::EBCDIC\n"; exit 0;
8b14f033 13 }
302cc833
GB
14}
15
406c51ee
JH
16use Net::Config;
17use Net::FTP;
18
8723f121
SH
19unless(defined($NetConfig{ftp_testhost})) {
20 print "1..0 # Skip: no ftp_testhost defined in config\n";
21 exit 0;
22}
23
24unless($NetConfig{test_hosts}) {
25 print "1..0 # Skip: test_hosts not enabled in config\n";
406c51ee
JH
26 exit 0;
27}
28
29my $t = 1;
30print "1..7\n";
31
686337f3 32$ftp = Net::FTP->new($NetConfig{ftp_testhost})
406c51ee
JH
33 or (print("not ok 1\n"), exit);
34
35printf "ok %d\n",$t++;
36
37$ftp->login('anonymous') or die($ftp->message . "\n");
38printf "ok %d\n",$t++;
39
40$ftp->pwd or do {
41 print STDERR $ftp->message,"\n";
42 print "not ";
43};
44
45printf "ok %d\n",$t++;
46
47$ftp->cwd('/pub') or do {
48 print STDERR $ftp->message,"\n";
49 print "not ";
50};
51
52if ($data = $ftp->stor('libnet.tst')) {
53 my $text = "abc\ndef\nqwe\n";
54 printf "ok %d\n",$t++;
55 $data->write($text,length $text);
56 $data->close;
57 $data = $ftp->retr('libnet.tst');
58 $data->read($buf,length $text);
59 $data->close;
60 print "not " unless $text eq $buf;
61 printf "ok %d\n",$t++;
62 $ftp->delete('libnet.tst') or print "not ";
63 printf "ok %d\n",$t++;
64
65}
66else {
686337f3
JH
67 print "# ",$ftp->message,"\n";
68 printf "ok %d\n",$t++;
69 printf "ok %d\n",$t++;
70 printf "ok %d\n",$t++;
406c51ee
JH
71}
72
73$ftp->quit or do {
74 print STDERR $ftp->message,"\n";
75 print "not ";
76};
77
78printf "ok %d\n",$t++;