Lines 37-58
Start the FTP transport connect, returns true on success or undefined on failure
Link Here
|
37 |
|
37 |
|
38 |
sub connect { |
38 |
sub connect { |
39 |
my ($self) = @_; |
39 |
my ($self) = @_; |
|
|
40 |
my $operation = "connection"; |
40 |
|
41 |
|
41 |
$self->{connection} = Net::FTP->new( |
42 |
$self->{connection} = Net::FTP->new( |
42 |
$self->host, |
43 |
$self->host, |
43 |
Port => $self->port, |
44 |
Port => $self->port, |
44 |
Timeout => $self->DEFAULT_TIMEOUT, |
45 |
Timeout => $self->DEFAULT_TIMEOUT, |
45 |
Passive => $self->passive ? 1 : 0, |
46 |
Passive => $self->passive ? 1 : 0, |
46 |
) or return $self->_abort_operation(); |
47 |
) or return $self->_abort_operation($operation); |
47 |
|
48 |
|
48 |
$self->{connection}->login( $self->user_name, $self->plain_text_password ) |
49 |
$self->{connection}->login( $self->user_name, $self->plain_text_password ) |
49 |
or return $self->_abort_operation(); |
50 |
or return $self->_abort_operation($operation); |
50 |
|
51 |
|
51 |
$self->add_message( |
52 |
$self->add_message( |
52 |
{ |
53 |
{ |
53 |
message => "Connect succeeded", |
54 |
message => $operation, |
54 |
type => 'success', |
55 |
type => 'success', |
55 |
payload => { detail => '' } |
56 |
payload => { |
|
|
57 |
status => 'connected', |
58 |
host => $self->host, |
59 |
port => $self->port |
60 |
} |
56 |
} |
61 |
} |
57 |
); |
62 |
); |
58 |
|
63 |
|
Lines 71-85
Returns true on success or undefined on failure.
Link Here
|
71 |
|
76 |
|
72 |
sub upload_file { |
77 |
sub upload_file { |
73 |
my ( $self, $local_file, $remote_file ) = @_; |
78 |
my ( $self, $local_file, $remote_file ) = @_; |
|
|
79 |
my $operation = "upload"; |
74 |
|
80 |
|
75 |
$self->{connection}->put( $local_file, $remote_file ) |
81 |
$self->{connection}->put( $local_file, $remote_file ) |
76 |
or return $self->_abort_operation(); |
82 |
or return $self->_abort_operation($operation); |
77 |
|
83 |
|
78 |
$self->add_message( |
84 |
$self->add_message( |
79 |
{ |
85 |
{ |
80 |
message => "Upload succeeded", |
86 |
message => $operation, |
81 |
type => 'success', |
87 |
type => 'success', |
82 |
payload => { detail => '' } |
88 |
payload => { |
|
|
89 |
local_file => $local_file, |
90 |
remote_file => $remote_file |
91 |
} |
83 |
} |
92 |
} |
84 |
); |
93 |
); |
85 |
|
94 |
|
Lines 98-112
Returns true on success or undefined on failure.
Link Here
|
98 |
|
107 |
|
99 |
sub download_file { |
108 |
sub download_file { |
100 |
my ( $self, $remote_file, $local_file ) = @_; |
109 |
my ( $self, $remote_file, $local_file ) = @_; |
|
|
110 |
my $operation = "download"; |
101 |
|
111 |
|
102 |
$self->{connection}->get( $remote_file, $local_file ) |
112 |
$self->{connection}->get( $remote_file, $local_file ) |
103 |
or return $self->_abort_operation(); |
113 |
or return $self->_abort_operation($operation); |
104 |
|
114 |
|
105 |
$self->add_message( |
115 |
$self->add_message( |
106 |
{ |
116 |
{ |
107 |
message => "Download succeeded", |
117 |
message => $operation, |
108 |
type => 'success', |
118 |
type => 'success', |
109 |
payload => { detail => '' } |
119 |
payload => { |
|
|
120 |
remote_file => $remote_file, |
121 |
local_file => $local_file |
122 |
} |
110 |
} |
123 |
} |
111 |
); |
124 |
); |
112 |
|
125 |
|
Lines 125-138
Returns true on success or undefined on failure.
Link Here
|
125 |
|
138 |
|
126 |
sub change_directory { |
139 |
sub change_directory { |
127 |
my ( $self, $remote_directory ) = @_; |
140 |
my ( $self, $remote_directory ) = @_; |
|
|
141 |
my $operation = "change_directory"; |
128 |
|
142 |
|
129 |
$self->{connection}->cwd($remote_directory) or $self->_abort_operation(); |
143 |
$self->{connection}->cwd($remote_directory) or return $self->_abort_operation($operation); |
130 |
|
144 |
|
131 |
$self->add_message( |
145 |
$self->add_message( |
132 |
{ |
146 |
{ |
133 |
message => "Changed directory succeeded", |
147 |
message => $operation, |
134 |
type => 'success', |
148 |
type => 'success', |
135 |
payload => { detail => '' } |
149 |
payload => { |
|
|
150 |
directory => $remote_directory, |
151 |
pwd => $self->{connection}->pwd |
152 |
} |
136 |
} |
153 |
} |
137 |
); |
154 |
); |
138 |
|
155 |
|
Lines 150-158
Each hashref contains: filename, longname, size, perms.
Link Here
|
150 |
|
167 |
|
151 |
sub list_files { |
168 |
sub list_files { |
152 |
my ($self) = @_; |
169 |
my ($self) = @_; |
|
|
170 |
my $operation = "list"; |
153 |
|
171 |
|
154 |
# Get detailed listing using dir() for consistency with SFTP format |
172 |
# Get detailed listing using dir() for consistency with SFTP format |
155 |
my $detailed_list = $self->{connection}->dir or return $self->_abort_operation(); |
173 |
my $detailed_list = $self->{connection}->dir or return $self->_abort_operation($operation); |
156 |
|
174 |
|
157 |
# Convert to hash format consistent with SFTP |
175 |
# Convert to hash format consistent with SFTP |
158 |
my @file_list; |
176 |
my @file_list; |
Lines 177-185
sub list_files {
Link Here
|
177 |
|
195 |
|
178 |
$self->add_message( |
196 |
$self->add_message( |
179 |
{ |
197 |
{ |
180 |
message => "Listing files succeeded", |
198 |
message => $operation, |
181 |
type => 'success', |
199 |
type => 'success', |
182 |
payload => { detail => '' } |
200 |
payload => { |
|
|
201 |
count => scalar @file_list, |
202 |
pwd => $self->{connection}->pwd |
203 |
} |
183 |
} |
204 |
} |
184 |
); |
205 |
); |
185 |
|
206 |
|
Lines 198-209
Returns true on success or undefined on failure.
Link Here
|
198 |
|
219 |
|
199 |
sub rename_file { |
220 |
sub rename_file { |
200 |
my ( $self, $old_name, $new_name ) = @_; |
221 |
my ( $self, $old_name, $new_name ) = @_; |
|
|
222 |
my $operation = "rename"; |
201 |
|
223 |
|
202 |
$self->{connection}->rename( $old_name, $new_name ) or return $self->_abort_operation(); |
224 |
$self->{connection}->rename( $old_name, $new_name ) or return $self->_abort_operation($operation); |
203 |
|
225 |
|
204 |
$self->add_message( |
226 |
$self->add_message( |
205 |
{ |
227 |
{ |
206 |
message => "File rename succeeded", |
228 |
message => $operation, |
207 |
type => 'success', |
229 |
type => 'success', |
208 |
payload => { detail => "$old_name -> $new_name" } |
230 |
payload => { detail => "$old_name -> $new_name" } |
209 |
} |
231 |
} |
Lines 232-244
sub disconnect {
Link Here
|
232 |
} |
254 |
} |
233 |
|
255 |
|
234 |
sub _abort_operation { |
256 |
sub _abort_operation { |
235 |
my ( $self, $message ) = @_; |
257 |
my ( $self, $operation ) = @_; |
236 |
|
258 |
|
237 |
$self->add_message( |
259 |
$self->add_message( |
238 |
{ |
260 |
{ |
239 |
message => $self->{connection} ? $self->{connection}->message : $@, |
261 |
message => $operation || 'operation', |
240 |
type => 'error', |
262 |
type => 'error', |
241 |
payload => { detail => $self->{connection} ? $self->{connection}->status : '' } |
263 |
payload => { |
|
|
264 |
detail => $self->{connection} ? $self->{connection}->status : '', |
265 |
error => $self->{connection} ? $self->{connection}->message : $@ |
266 |
} |
242 |
} |
267 |
} |
243 |
); |
268 |
); |
244 |
|
269 |
|
245 |
- |
|
|