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