| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # $Id: FTP.pm,v 1.7 2005/02/18 14:03:39 cmuellermeta Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright (C) 2001,2002 Online Office Berlin. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Copyright (c) 2002 Slaven Rezic. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # terms of the GNU General Public License, see the file COPYING. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # Mail: slaven@rezic.de | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # WWW: http://we-framework.sourceforge.net | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | package WE_Frontend::Publish::FTP; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | package WE_Frontend::Main; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use WE_Frontend::Publish; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ($] < 5.006) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $INC{"warnings.pm"}++; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | eval q{ | |||||||||||||||||||||||||||||||||||||||||
| 33 | package warnings; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | sub unimport { } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | }; die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use WE::Util::Functions qw(_save_pwd); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub publish_ftp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
publish_ftp: not called CC=20 SCAR=60.1
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $v = delete $args{-verbose}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $liveuser = $self->Config->staging->user; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $livepassword = $self->Config->staging->password; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $livedirectory = $self->Config->staging->directory; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $livecgidirectory = $self->Config->staging->cgidirectory; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $livehost = $self->Config->staging->host; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $pubhtmldir = $self->Config->paths->pubhtmldir; | |||||||||||||||||||||||||||||||||||||||||
| 55 | my @extracgi = (ref $self->Config->project->stagingextracgi eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | ? @{ $self->Config->project->stagingextracgi } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | : () | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (!defined $liveuser || $liveuser eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $liveuser or $liveuser eq ""
MC/DC0%0/2
not defined $liveuser or $liveuser eq ""
not defined $liveuser
$liveuser eq ""
Truth table0%0/3
not(A) or B
A= not defined $liveuserB= $liveuser eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | die "The FTP user is missing (config member WEsiteinfo->staging->user)"; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (!defined $livepassword || $livepassword eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $livepassword or $livepassword eq ""
MC/DC0%0/2
not defined $livepassword or $livepassword eq ""
not defined $livepassword
$livepassword eq ""
Truth table0%0/3
not(A) or B
A= not defined $livepasswordB= $livepassword eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | die "The FTP password is missing (config member WEsiteinfo->staging->password)"; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if (!defined $livehost || $livehost eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $livehost or $livehost eq ""
MC/DC0%0/2
not defined $livehost or $livehost eq ""
not defined $livehost
$livehost eq ""
Truth table0%0/3
not(A) or B
A= not defined $livehostB= $livehost eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die "The target FTP host is missing (config member WEsiteinfo->staging->host)"; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (!defined $pubhtmldir || $pubhtmldir eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $pubhtmldir or $pubhtmldir eq ""
MC/DC0%0/2
not defined $pubhtmldir or $pubhtmldir eq ""
not defined $pubhtmldir
$pubhtmldir eq ""
Truth table0%0/3
not(A) or B
A= not defined $pubhtmldirB= $pubhtmldir eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | die "The publish html directory is missing (config member WEsiteinfo->paths->pubhtmldir)"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (@extracgi && (!defined $livecgidirectory || $livecgidirectory eq '')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@extracgi and !defined($livecgidirectory) || $livecgidirectory eq ""
not defined $livecgidirectory or $livecgidirectory eq ""
MC/DC0%0/3
@extracgi and !defined($livecgidirectory) || $livecgidirectory eq ""
@extracgi
not defined $livecgidirectory
$livecgidirectory eq ""
Truth table0%0/4
A and not(B) or C
A= @extracgiB= not defined $livecgidirectoryC= $livecgidirectory eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | die "Extra CGI scripts are defined (@extracgi), | |||||||||||||||||||||||||||||||||||||||||
| 74 | but the WEsiteinfo->staging->cgidirectory config is missing"; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | print <<EOF | |||||||||||||||||||||||||||||||||||||||||
| 79 | Using FTP Protocol. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | FTP remote host: $livehost | ||||||||||||||||||||||||||||||||||||||||||
| 81 | FTP remote user: $liveuser | ||||||||||||||||||||||||||||||||||||||||||
| 82 | FTP remote directory: $livedirectory | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | @{[ @extracgi ? "FTP remote CGI directory: $livecgidirectory" : "" ]} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $ftp = Net::FTP->new($livehost, Debug => 0) or die "Can't open FTP connection to $livehost: $@"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $ftp->login($liveuser, $livepassword) or die "Can't login with $liveuser"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $ftp->pasv(); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $ftp->binary(); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (defined $livedirectory && $livedirectory ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $livedirectory and $livedirectory ne ""
MC/DC0%0/2
defined $livedirectory and $livedirectory ne ""
defined $livedirectory
$livedirectory ne ""
Truth table0%0/3
A and B
A= defined $livedirectoryB= $livedirectory ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $ftp->cwd($livedirectory) or die "Can't remote chdir to $livedirectory"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $ret = WE_Frontend::Publish::get_files_to_publish($self, %args); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my @directories = @{ $ret->{Directories} }; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my @files = @{ $ret->{Files} }; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | _save_pwd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | chdir $pubhtmldir || die "Can't change directory to $pubhtmldir: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | foreach my $dir (@directories) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($v) { print "Create folder $dir\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $ftp->mkdir($dir); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | foreach my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($v) { print "Create document $file\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (!-r $file) { warn "The local file $pubhtmldir/$file is not readable" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $ftp->put($file, $file) or warn "Can't put $pubhtmldir/$file to remote host $livehost"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return {Directories => \@directories, | |||||||||||||||||||||||||||||||||||||||||
| 117 | Files => \@files, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||||||||||||||||