|
Lines 548-553
sub download_file {
Link Here
|
| 548 |
return $self->_download_file( $remote_file, $local_file ); |
548 |
return $self->_download_file( $remote_file, $local_file ); |
| 549 |
} |
549 |
} |
| 550 |
|
550 |
|
|
|
551 |
=head3 delete_file |
| 552 |
|
| 553 |
my $success = $transport->delete_file($remote_file, \%options); |
| 554 |
|
| 555 |
Deletes a file from the remote server. Automatically establishes a connection if needed. |
| 556 |
|
| 557 |
B<Parameters:> |
| 558 |
|
| 559 |
=over 4 |
| 560 |
|
| 561 |
=item * C<$remote_file> - Remote filename (not a path, just the filename) (required) |
| 562 |
|
| 563 |
=item * C<\%options> - Optional hashref with keys: |
| 564 |
|
| 565 |
=over 4 |
| 566 |
|
| 567 |
=item * C<path> - Directory path containing the file. If provided, uses this directory |
| 568 |
for this operation only (simplified API). If omitted, behavior depends on whether |
| 569 |
change_directory() has been called explicitly (see DESCRIPTION). |
| 570 |
|
| 571 |
=back |
| 572 |
|
| 573 |
=back |
| 574 |
|
| 575 |
B<Usage Patterns:> |
| 576 |
|
| 577 |
# Pattern 1: Simplified API with custom path |
| 578 |
$transport->delete_file('old.txt', { path => '/temp/' }); |
| 579 |
|
| 580 |
# Pattern 2: Simplified API with configured download_directory |
| 581 |
$transport->delete_file('old.txt'); |
| 582 |
|
| 583 |
# Pattern 3: Traditional API with explicit directory |
| 584 |
$transport->change_directory('/temp/'); |
| 585 |
$transport->delete_file('old.txt'); |
| 586 |
|
| 587 |
B<Returns:> True on success, undef on failure. Check object_messages() for details. |
| 588 |
|
| 589 |
=cut |
| 590 |
|
| 591 |
sub delete_file { |
| 592 |
my ( $self, $remote_file, $options ) = @_; |
| 593 |
|
| 594 |
return unless $self->_ensure_connected(); |
| 595 |
|
| 596 |
# Only auto-change directory if: |
| 597 |
# 1. Options provided with custom path (simplified API), OR |
| 598 |
# 2. No explicit directory set by user AND default download_directory exists (traditional API) |
| 599 |
if ( $options && $options->{path} ) { |
| 600 |
|
| 601 |
# Simplified API - use custom path |
| 602 |
return unless $self->_auto_change_directory( 'download', $options->{path} ); |
| 603 |
} elsif ( !$self->{_user_set_directory} ) { |
| 604 |
|
| 605 |
# Traditional API - use default directory only if user hasn't set one |
| 606 |
return unless $self->_auto_change_directory( 'download', undef ); |
| 607 |
} |
| 608 |
|
| 609 |
return $self->_delete_file($remote_file); |
| 610 |
} |
| 611 |
|
| 612 |
=head3 _delete_file |
| 613 |
|
| 614 |
$transport->_delete_file($remote_file); |
| 615 |
|
| 616 |
Internal method that performs the protocol-specific file deletion operation. |
| 617 |
Must be implemented by subclasses. Called by delete_file after connection |
| 618 |
and directory management. |
| 619 |
|
| 620 |
=cut |
| 621 |
|
| 622 |
sub _delete_file { |
| 623 |
my ($self) = @_; |
| 624 |
die "Subclass must implement _delete_file"; |
| 625 |
} |
| 626 |
|
| 551 |
=head3 _download_file |
627 |
=head3 _download_file |
| 552 |
|
628 |
|
| 553 |
$transport->_download_file($remote_file, $local_file); |
629 |
$transport->_download_file($remote_file, $local_file); |