|
Lines 397-402
sub rename_file {
Link Here
|
| 397 |
return 1; |
397 |
return 1; |
| 398 |
} |
398 |
} |
| 399 |
|
399 |
|
|
|
400 |
=head3 delete_file |
| 401 |
|
| 402 |
$server->delete_file(); |
| 403 |
|
| 404 |
Deletes a file in the current directory. |
| 405 |
|
| 406 |
Returns true on success or undefined on failure. |
| 407 |
|
| 408 |
=cut |
| 409 |
|
| 410 |
sub delete_file { |
| 411 |
my ( $self, $remote_file ) = @_; |
| 412 |
my $operation = "delete"; |
| 413 |
|
| 414 |
my $directory = $self->download_directory || $self->{current_directory} || '.'; |
| 415 |
my $source = File::Spec->catfile( $directory, $remote_file ); |
| 416 |
|
| 417 |
# Check if the file exists |
| 418 |
unless ( -e $source ) { |
| 419 |
$self->add_message( |
| 420 |
{ |
| 421 |
message => $operation, |
| 422 |
type => 'error', |
| 423 |
payload => { |
| 424 |
error => "File not found: $source", |
| 425 |
path => $source |
| 426 |
} |
| 427 |
} |
| 428 |
); |
| 429 |
return; |
| 430 |
} |
| 431 |
|
| 432 |
# Attempt to delete the file |
| 433 |
if ( unlink $source ) { |
| 434 |
$self->add_message( |
| 435 |
{ |
| 436 |
message => $operation, |
| 437 |
type => 'success', |
| 438 |
payload => { path => $source } |
| 439 |
} |
| 440 |
); |
| 441 |
} else { |
| 442 |
$self->add_message( |
| 443 |
{ |
| 444 |
message => $operation, |
| 445 |
type => 'error', |
| 446 |
payload => { |
| 447 |
error => "File could not be deleted: $source", |
| 448 |
path => $source |
| 449 |
} |
| 450 |
} |
| 451 |
); |
| 452 |
} |
| 453 |
|
| 454 |
return 1; |
| 455 |
} |
| 456 |
|
| 400 |
=head3 disconnect |
457 |
=head3 disconnect |
| 401 |
|
458 |
|
| 402 |
$server->disconnect(); |
459 |
$server->disconnect(); |