Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.0 KiB

  1. # ======================================================================
  2. #
  3. # Copyright (C) 2000-2001 Paul Kulchenko ([email protected])
  4. # SOAP::Lite is free software; you can redistribute it
  5. # and/or modify it under the same terms as Perl itself.
  6. #
  7. # $Id: SOAP::Transport::FTP.pm,v 0.50 2001/04/18 11:45:14 $
  8. #
  9. # ======================================================================
  10. package SOAP::Transport::FTP;
  11. use strict;
  12. use vars qw($VERSION);
  13. $VERSION = '0.50';
  14. use Net::FTP;
  15. use IO::File;
  16. use URI;
  17. # ======================================================================
  18. package SOAP::Transport::FTP::Client;
  19. use vars qw(@ISA);
  20. @ISA = qw(SOAP::Client);
  21. sub new {
  22. my $self = shift;
  23. my $class = ref($self) || $self;
  24. unless (ref $self) {
  25. my $class = ref($self) || $self;
  26. my(@params, @methods);
  27. while (@_) { $class->can($_[0]) ? push(@methods, shift() => shift) : push(@params, shift) }
  28. $self = bless {@params} => $class;
  29. while (@methods) { my($method, $params) = splice(@methods,0,2);
  30. $self->$method(ref $params eq 'ARRAY' ? @$params : $params)
  31. }
  32. }
  33. return $self;
  34. }
  35. sub send_receive {
  36. my($self, %parameters) = @_;
  37. my($envelope, $endpoint, $action) =
  38. @parameters{qw(envelope endpoint action)};
  39. $endpoint ||= $self->endpoint; # ftp://login:[email protected]/dir/file
  40. my $uri = URI->new($endpoint);
  41. my($server, $auth) = reverse split /@/, $uri->authority;
  42. my $dir = substr($uri->path, 1, rindex($uri->path, '/'));
  43. my $file = substr($uri->path, rindex($uri->path, '/')+1);
  44. eval {
  45. my $ftp = Net::FTP->new($server, %$self) or die "Can't connect to $server: $@\n";
  46. $ftp->login(split /:/, $auth) or die "Couldn't login\n";
  47. $dir and ($ftp->cwd($dir) or
  48. $ftp->mkdir($dir, 'recurse') and $ftp->cwd($dir) or die "Couldn't change directory to '$dir'\n");
  49. my $FH = IO::File->new_tmpfile; print $FH $envelope; $FH->flush; $FH->seek(0,0);
  50. $ftp->put($FH => $file) or die "Couldn't put file '$file'\n";
  51. $ftp->quit;
  52. };
  53. (my $code = $@) =~ s/\n$//;
  54. $self->code($code);
  55. $self->message($code);
  56. $self->is_success(!defined $code || $code eq '');
  57. $self->status($code);
  58. return;
  59. }
  60. # ======================================================================
  61. 1;
  62. __END__
  63. =head1 NAME
  64. SOAP::Transport::FTP - Client side FTP support for SOAP::Lite
  65. =head1 SYNOPSIS
  66. use SOAP::Lite
  67. uri => 'http://my.own.site.com/My/Examples',
  68. proxy => 'ftp://login:[email protected]/relative/path/to/file.xml', # ftp server
  69. # proxy => 'ftp://login:[email protected]//absolute/path/to/file.xml', # ftp server
  70. ;
  71. print getStateName(1);
  72. =head1 DESCRIPTION
  73. =head1 COPYRIGHT
  74. Copyright (C) 2000-2001 Paul Kulchenko. All rights reserved.
  75. This library is free software; you can redistribute it and/or modify
  76. it under the same terms as Perl itself.
  77. =head1 AUTHOR
  78. Paul Kulchenko (paulclinger@yahoo.com)
  79. =cut