21
22
# ======================================================================
23
24
package SOAP::Transport::FTP::Client;
26
27
@ISA = qw(SOAP::Client);
30
my $class = ref($self) || $self;
31
return $class if ref $class;
33
my $class = ref($self) || $self;
34
my(@params, @methods);
35
while (@_) { $class->can($_[0]) ? push(@methods, shift() => shift) : push(@params, shift) }
36
$self = bless {@params} => $class;
37
while (@methods) { my($method, $params) = splice(@methods,0,2);
38
$self->$method(ref $params eq 'ARRAY' ? @$params : $params)
33
my(@arg_from, @method_from);
36
? push(@method_from, shift() => shift)
37
: push(@arg_from, shift)
39
my $self = bless {@arg_from} => $class;
40
while (@method_from) {
41
my($method, $param_ref) = splice(@method_from,0,2);
42
$self->$method(ref $param_ref eq 'ARRAY' ? @$param_ref : $param_ref)
45
my($self, %parameters) = @_;
46
my($envelope, $endpoint, $action) =
47
@parameters{qw(envelope endpoint action)};
49
$endpoint ||= $self->endpoint; # ftp://login:password@ftp.something/dir/file
51
my $uri = URI->new($endpoint);
52
my($server, $auth) = reverse split /@/, $uri->authority;
53
my $dir = substr($uri->path, 1, rindex($uri->path, '/'));
54
my $file = substr($uri->path, rindex($uri->path, '/')+1);
57
my $ftp = Net::FTP->new($server, %$self) or die "Can't connect to $server: $@\n";
58
$ftp->login(split /:/, $auth) or die "Couldn't login\n";
59
$dir and ($ftp->cwd($dir) or
60
$ftp->mkdir($dir, 'recurse') and $ftp->cwd($dir) or die "Couldn't change directory to '$dir'\n");
62
my $FH = IO::File->new_tmpfile; print $FH $envelope; $FH->flush; $FH->seek(0,0);
63
$ftp->put($FH => $file) or die "Couldn't put file '$file'\n";
67
(my $code = $@) =~ s/\n$//;
70
$self->message($code);
71
$self->is_success(!defined $code || $code eq '');
48
my($self, %parameters) = @_;
49
my($envelope, $endpoint, $action) =
50
@parameters{qw(envelope endpoint action)};
52
$endpoint ||= $self->endpoint; # ftp://login:password@ftp.something/dir/file
54
my $uri = URI->new($endpoint);
55
my($server, $auth) = reverse split /@/, $uri->authority;
56
my $dir = substr($uri->path, 1, rindex($uri->path, '/'));
57
my $file = substr($uri->path, rindex($uri->path, '/')+1);
60
my $ftp = Net::FTP->new($server, %$self) or die "Can't connect to $server: $@\n";
61
$ftp->login(split /:/, $auth) or die "Couldn't login\n";
62
$dir and ($ftp->cwd($dir)
63
or $ftp->mkdir($dir, 'recurse') and $ftp->cwd($dir)
64
or die "Couldn't change directory to '$dir'\n");
66
my $FH = IO::File->new_tmpfile; print $FH $envelope; $FH->flush; $FH->seek(0,0);
67
$ftp->put($FH => $file) or die "Couldn't put file '$file'\n";
71
(my $code = $@) =~ s/\n$//;
74
$self->message($code);
75
$self->is_success(!defined $code || $code eq '');
77
81
# ======================================================================
85
SOAP::Transport::FTP - Client side FTP support for SOAP::Lite
90
uri => 'http://my.own.site.com/My/Examples',
91
proxy => 'ftp://login:password@ftp.somewhere.com/relative/path/to/file.xml', # ftp server
92
# proxy => 'ftp://login:password@ftp.somewhere.com//absolute/path/to/file.xml', # ftp server
95
print getStateName(1);
101
Copyright (C) 2000-2001 Paul Kulchenko. All rights reserved.
103
This library is free software; you can redistribute it and/or modify
104
it under the same terms as Perl itself.
108
Paul Kulchenko (paulclinger@yahoo.com)