Bug 35724: (QA follow-up) Also account for port in FTP

We were only passing port into SFTP connections.. now that we allow
defining it, we should also pass it to FTP connections just in case
someone is still using those.

This patch adds such functionality and defaults to port 21 in this case
when the port isn't defined.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2024-02-27 11:08:59 +00:00 committed by Katrin Fischer
parent e881ace64a
commit d1bd2e9c03
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 16 additions and 8 deletions

View File

@ -219,13 +219,17 @@ sub ftp_download {
my $msg_hash = $self->message_hash();
my @downloaded_files;
my $ftp = Net::FTP->new(
my $port = $self->{account}->download_port ? $self->{account}->download_port : '21';
my $ftp = Net::FTP->new(
$self->{account}->host,
Port => $port,
Timeout => 10,
Passive => 1
)
or return $self->_abort_download( undef,
"Cannot connect to $self->{account}->host: $EVAL_ERROR" );
)
or return $self->_abort_download(
undef,
"Cannot connect to $self->{account}->host: $EVAL_ERROR"
);
$ftp->login( $self->{account}->username, Koha::Encryption->new->decrypt_hex($self->{account}->password) )
or return $self->_abort_download( $ftp, "Cannot login: $ftp->message()" );
$ftp->cwd( $self->{account}->download_directory )
@ -260,13 +264,17 @@ sub ftp_download {
sub ftp_upload {
my ( $self, @messages ) = @_;
my $ftp = Net::FTP->new(
my $port = $self->{account}->upload_port ? $self->{account}->upload_port : '21';
my $ftp = Net::FTP->new(
$self->{account}->host,
Port => $port,
Timeout => 10,
Passive => 1
)
or return $self->_abort_download( undef,
"Cannot connect to $self->{account}->host: $EVAL_ERROR" );
)
or return $self->_abort_download(
undef,
"Cannot connect to $self->{account}->host: $EVAL_ERROR"
);
$ftp->login( $self->{account}->username, Koha::Encryption->new->decrypt_hex($self->{account}->password) )
or return $self->_abort_download( $ftp, "Cannot login: $ftp->message()" );
$ftp->cwd( $self->{account}->upload_directory )