1b8851fccSafresh1#!perl 2b8851fccSafresh1 3b8851fccSafresh1use 5.008001; 4b8851fccSafresh1 5b8851fccSafresh1use strict; 6b8851fccSafresh1use warnings; 7b39c5158Smillert 8b39c5158SmillertBEGIN { 9b8851fccSafresh1 if (!eval { require Socket }) { 10*eac174f2Safresh1 print "1..0 # Skip: no Socket\n"; exit 0; 11b39c5158Smillert } 12b8851fccSafresh1 if (ord('A') == 193 && !eval { require Convert::EBCDIC }) { 13c87e12b9Sjasper print "1..0 # Skip: EBCDIC but no Convert::EBCDIC\n"; exit 0; 14b39c5158Smillert } 15b39c5158Smillert} 16b39c5158Smillert 17b39c5158Smillertuse Net::Config; 18b39c5158Smillertuse Net::FTP; 19b39c5158Smillert 20c87e12b9Sjasperunless(defined($NetConfig{ftp_testhost})) { 21c87e12b9Sjasper print "1..0 # Skip: no ftp_testhost defined in config\n"; 22c87e12b9Sjasper exit 0; 23c87e12b9Sjasper} 24c87e12b9Sjasper 25c87e12b9Sjasperunless($NetConfig{test_hosts}) { 26c87e12b9Sjasper print "1..0 # Skip: test_hosts not enabled in config\n"; 27b39c5158Smillert exit 0; 28b39c5158Smillert} 29b39c5158Smillert 30b39c5158Smillertmy $t = 1; 31b39c5158Smillertprint "1..7\n"; 32b39c5158Smillert 33b8851fccSafresh1my $ftp = Net::FTP->new($NetConfig{ftp_testhost}) 34b39c5158Smillert or (print("not ok 1\n"), exit); 35b39c5158Smillert 36b39c5158Smillertprintf "ok %d\n",$t++; 37b39c5158Smillert 38b39c5158Smillert$ftp->login('anonymous') or die($ftp->message . "\n"); 39b39c5158Smillertprintf "ok %d\n",$t++; 40b39c5158Smillert 41b39c5158Smillert$ftp->pwd or do { 42b39c5158Smillert print STDERR $ftp->message,"\n"; 43b39c5158Smillert print "not "; 44b39c5158Smillert}; 45b39c5158Smillert 46b39c5158Smillertprintf "ok %d\n",$t++; 47b39c5158Smillert 48b39c5158Smillert$ftp->cwd('/pub') or do { 49b39c5158Smillert print STDERR $ftp->message,"\n"; 50b39c5158Smillert print "not "; 51b39c5158Smillert}; 52b39c5158Smillert 53b8851fccSafresh1my $data; 54b39c5158Smillertif ($data = $ftp->stor('libnet.tst')) { 55b39c5158Smillert my $text = "abc\ndef\nqwe\n"; 56b39c5158Smillert printf "ok %d\n",$t++; 57b39c5158Smillert $data->write($text,length $text); 58b39c5158Smillert $data->close; 59b39c5158Smillert $data = $ftp->retr('libnet.tst'); 60b8851fccSafresh1 my $buf; 61b39c5158Smillert $data->read($buf,length $text); 62b39c5158Smillert $data->close; 63b39c5158Smillert print "not " unless $text eq $buf; 64b39c5158Smillert printf "ok %d\n",$t++; 65b39c5158Smillert $ftp->delete('libnet.tst') or print "not "; 66b39c5158Smillert printf "ok %d\n",$t++; 67b39c5158Smillert 68b39c5158Smillert} 69b39c5158Smillertelse { 70b39c5158Smillert print "# ",$ftp->message,"\n"; 71b39c5158Smillert printf "ok %d\n",$t++; 72b39c5158Smillert printf "ok %d\n",$t++; 73b39c5158Smillert printf "ok %d\n",$t++; 74b39c5158Smillert} 75b39c5158Smillert 76b39c5158Smillert$ftp->quit or do { 77b39c5158Smillert print STDERR $ftp->message,"\n"; 78b39c5158Smillert print "not "; 79b39c5158Smillert}; 80b39c5158Smillert 81b39c5158Smillertprintf "ok %d\n",$t++; 82