]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/ftp.pl
932c719c775f9ab2006f435c6d5bbcbc13add5fb
[working/Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / ftp.pl
1 #!/usr/bin/perl -IOpen-ILS/src/perlmods 
2
3 use strict; use warnings;
4
5 use Data::Dumper;
6
7 use OpenILS::Utils::RemoteAccount;
8
9 my $delay = 1;
10
11 my %config = (
12     remote_host => 'example.org',
13     remote_user => 'some_user',
14     remote_password => 'some_user',
15     remote_file => './out/testfile',
16 );
17
18 sub content {
19     my $time = localtime;
20     return <<END_OF_CONTENT;
21
22 This is a test file sent at:
23 $time
24
25 END_OF_CONTENT
26 }
27
28 my $x = OpenILS::Utils::RemoteAccount->new(
29     remote_host => $config{remote_host},
30     remote_user => $config{remote_user},
31     content => content(),
32 );
33
34 $Data::Dumper::Indent = 1;
35 print Dumper($x);
36
37 $delay and print "Sleeping $delay seconds\n" and sleep $delay;
38
39 $x->put({
40     remote_file => $config{remote_file} . "1.$$",
41     content     => content(),
42 }) or die "ERROR: $x->error";
43
44 print "\n\n", Dumper($x);
45
46 my $file = $x->local_file;
47 open TEMP, "< $file" or die "Cannot read tempfile $file: $!";
48 print "\n\ncontent from tempfile $file:\n";
49 while (my $line = <TEMP>) {
50     print $line;
51 }
52 close TEMP;
53
54 print "\n\nls :\n", join "\n", $x->ls;
55 print "\n\nls ('out'):\n", join "\n", $x->ls('out');
56
57 print "\nThis one should fail (at put)\n";
58 my $y;
59
60 $y = OpenILS::Utils::RemoteAccount->new(
61     remote_host     => $config{remote_host},
62     remote_user     => $config{remote_user},
63     remote_password => 'some_junk',
64     content => content(),
65     type => 'FTP',
66 );
67 print STDERR "ERROR: $@ $! : \n", $y->error, "\n";
68
69 print "\n\n", Dumper($y);
70
71 $delay and print "Sleeping $delay seconds\n" and sleep $delay;
72 $y->put({
73     remote_file => $config{remote_file} . "2.$$",
74     content     => content(),
75 }) or warn "ERROR with put: " . $y->error;
76
77 print "\nThis one might succeed\n";
78 $y->put({
79     remote_file => $config{remote_file} . "3.$$",
80     content     => content(),
81     remote_password => $config{remote_password},
82 }) or warn "ERROR with put: " . $y->error;
83