602
|
1 |
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
#
|
|
15 |
#
|
|
16 |
# Description:
|
|
17 |
# RemoteSite::FTP::Proxy.pm
|
|
18 |
#
|
|
19 |
|
|
20 |
package RemoteSite::FTP::Proxy;
|
|
21 |
|
|
22 |
use strict;
|
|
23 |
use Net::FTP;
|
|
24 |
|
|
25 |
use RemoteSite::FTP;
|
|
26 |
use vars qw(@ISA);
|
|
27 |
@ISA=("RemoteSite::FTP");
|
|
28 |
|
|
29 |
#
|
|
30 |
# Initialization
|
|
31 |
#
|
|
32 |
|
|
33 |
sub Initialize {
|
|
34 |
my $self = shift;
|
|
35 |
|
|
36 |
my %args = @_;
|
|
37 |
$self->{proxy} = $args{proxy};
|
|
38 |
$self->{proxyUsername} = $args{proxy_username};
|
|
39 |
$self->{proxyPassword} = $args{proxy_password};
|
|
40 |
|
|
41 |
#if proxy username or password not defined ask for them interactively
|
|
42 |
unless ($self->ProxyUsername()) {
|
|
43 |
print 'Proxy FTP username: ';
|
|
44 |
my $userName = <STDIN>;
|
|
45 |
if ($userName) {
|
|
46 |
chomp ($userName);
|
|
47 |
$self->ProxyUsername($userName);
|
|
48 |
}
|
|
49 |
}
|
|
50 |
unless ($self->ProxyPassword()) {
|
|
51 |
print 'Proxy FTP password: ';
|
|
52 |
$self->ProxyPassword(Utils::QueryPassword());
|
|
53 |
}
|
|
54 |
|
|
55 |
#call base class initialization
|
|
56 |
$self->SUPER::Initialize(@_);
|
|
57 |
}
|
|
58 |
|
|
59 |
#
|
|
60 |
# Public getters/setters
|
|
61 |
#
|
|
62 |
|
|
63 |
sub Proxy {
|
|
64 |
my $self = shift;
|
|
65 |
if (defined $_[0]) {$self->{proxy} = shift;}
|
|
66 |
return $self->{proxy};
|
|
67 |
}
|
|
68 |
|
|
69 |
sub ProxyUsername {
|
|
70 |
my $self = shift;
|
|
71 |
if (defined $_[0]) {$self->{proxyUsername} = shift;}
|
|
72 |
return $self->{proxyUsername};
|
|
73 |
}
|
|
74 |
|
|
75 |
sub ProxyPassword {
|
|
76 |
my $self = shift;
|
|
77 |
if (defined $_[0]) {$self->{proxyPassword} = shift;}
|
|
78 |
return $self->{proxyPassword};
|
|
79 |
}
|
|
80 |
|
|
81 |
#
|
|
82 |
# Private
|
|
83 |
#
|
|
84 |
|
|
85 |
sub Connect {
|
|
86 |
my $self = shift;
|
|
87 |
|
|
88 |
unless ($self->Proxy()) {
|
|
89 |
$self->HandleError("Cannot connect to proxy, host name not defined");
|
|
90 |
}
|
|
91 |
unless ($self->Host()) {
|
|
92 |
$self->HandleError("Cannot connect to FTP site from proxy, host name not defined");
|
|
93 |
}
|
|
94 |
|
|
95 |
my $debug = (($self->{verbose} > 1) ? 1 : 0);
|
|
96 |
|
|
97 |
#Attempt to connect (or reconnect of connection fails)
|
|
98 |
for (1..$self->Reconnects()) {
|
|
99 |
$self->{ftp} = undef;
|
|
100 |
if ($self->{verbose}) {
|
|
101 |
print "Connecting to proxy server ".$self->Proxy()."...\n";
|
|
102 |
}
|
|
103 |
$self->{ftp} = Net::FTP->new($self->Proxy(),
|
|
104 |
Passive => $self->PassiveMode(),
|
|
105 |
Debug => $debug,
|
|
106 |
Timeout => $self->Timeout());
|
|
107 |
if (defined $self->{ftp}) {
|
|
108 |
# code to support Blue Coat proxy ftp server
|
|
109 |
|
|
110 |
if ($self->{ftp}->message =~ /Blue Coat Ftp Service/) {
|
|
111 |
# do BC login
|
|
112 |
$self->{ftp}->login($self->Username().'@'.$self->Host()." ".$self->ProxyUsername(),
|
|
113 |
$self->Password(),
|
|
114 |
$self->ProxyPassword())
|
|
115 |
or $self->HandleError("FTP via Blue Coat proxy login failed");
|
|
116 |
}
|
|
117 |
else {
|
|
118 |
#login to proxy server
|
|
119 |
$self->{ftp}->login($self->ProxyUsername(), $self->ProxyPassword())
|
|
120 |
or $self->HandleError("Proxy server login failed");
|
|
121 |
|
|
122 |
#login to ftp site from proxy server
|
|
123 |
$self->{ftp}->login($self->Username().'@'.$self->Host(), $self->Password())
|
|
124 |
or $self->HandleError("FTP login failed");
|
|
125 |
}
|
|
126 |
#change transfer mode to binary
|
|
127 |
$self->{ftp}->binary()
|
|
128 |
or $self->HandleError("Failed to set FTP server to binary transfer mode");
|
|
129 |
return;
|
|
130 |
}
|
|
131 |
}
|
|
132 |
$self->HandleError("Cannot connect to proxy server ".$self->Proxy());
|
|
133 |
}
|
|
134 |
|
|
135 |
1;
|
|
136 |
|
|
137 |
=head1 NAME
|
|
138 |
|
|
139 |
RemoteSite::FTP::Proxy.pm - Access a remote FTP site via a proxy.
|
|
140 |
|
|
141 |
=head1 SYNOPSIS
|
|
142 |
|
|
143 |
use RemoteSite::FTP::Proxy;
|
|
144 |
|
|
145 |
$ftp = RemoteSite::FTP::Proxy->New(host => 'ftp.somehost.com',
|
|
146 |
username => 'myusername',
|
|
147 |
password => 'mypassword',
|
|
148 |
proxy => 'ftp.proxyhost.com',
|
|
149 |
proxy_username => 'myproxyuser',
|
|
150 |
proxy_password => 'myproxypass',
|
|
151 |
verbose => 1);
|
|
152 |
|
|
153 |
if ($ftp->FileExists('/somedir/someremotefile')) {
|
|
154 |
do something...
|
|
155 |
}
|
|
156 |
$ftp->SendFile('somelocalfile', 'someremotefile');
|
|
157 |
$ftp->GetFile('someremotefile', 'somelocalfile');
|
|
158 |
|
|
159 |
=head1 DESCRIPTION
|
|
160 |
|
|
161 |
C<RemoteSite::FTP::Proxy> is inherited from C<RemoteSite::FTP>, it modifies base module methods to implement accessing an FTP site via a proxy server
|
|
162 |
|
|
163 |
=head1 INTERFACE
|
|
164 |
|
|
165 |
=head2 New
|
|
166 |
|
|
167 |
Passed an argument list in the form of hash key value pairs. The supported arguments are...
|
|
168 |
|
|
169 |
host => $host_address_string
|
|
170 |
username => $user_name_string
|
|
171 |
password => $pass_word_string
|
|
172 |
proxy => $proxy_address_string
|
|
173 |
proxy_username => $proxy_username_string
|
|
174 |
proxy_password => $proxy_password_string
|
|
175 |
verbose => $verbosity_integer
|
|
176 |
|
|
177 |
Returns a reference to a C<RemoteSite::FTP::Proxy> object
|
|
178 |
|
|
179 |
=head2 Proxy
|
|
180 |
|
|
181 |
Returns the current value of the C<proxy> attribute which contains the proxy FTP address. If passed an argument sets the attribute to this new value.
|
|
182 |
|
|
183 |
=head2 ProxyUsername
|
|
184 |
|
|
185 |
Returns the current value of the C<proxyUsername> attribute which stores the user name required to access the proxy FTP site. If passed an argument sets the attribute to this new value.
|
|
186 |
|
|
187 |
=head2 ProxyPassword
|
|
188 |
|
|
189 |
Returns the current value of the C<proxyPassword> attribute which stores the password required to access the proxy FTP site. If passed an argument sets the attribute to this new value.
|
|
190 |
|
|
191 |
=head1 KNOWN BUGS
|
|
192 |
|
|
193 |
None
|
|
194 |
|
|
195 |
=head1 COPYRIGHT
|
|
196 |
|
|
197 |
Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
198 |
All rights reserved.
|
|
199 |
This component and the accompanying materials are made available
|
|
200 |
under the terms of the License "Eclipse Public License v1.0"
|
|
201 |
which accompanies this distribution, and is available
|
|
202 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
203 |
|
|
204 |
Initial Contributors:
|
|
205 |
Nokia Corporation - initial contribution.
|
|
206 |
|
|
207 |
Contributors:
|
|
208 |
|
|
209 |
Description:
|
|
210 |
|
|
211 |
|
|
212 |
=cut
|