|
Lines 17-35
package Koha::Edifact::Transport;
Link Here
|
| 17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use strict; |
20 |
use Modern::Perl; |
| 21 |
use warnings; |
21 |
|
| 22 |
use utf8; |
22 |
use utf8; |
| 23 |
use DateTime; |
23 |
|
| 24 |
use Carp qw( carp ); |
24 |
use Carp qw( carp ); |
|
|
25 |
use DateTime; |
| 26 |
use Encode qw( from_to ); |
| 25 |
use English qw{ -no_match_vars }; |
27 |
use English qw{ -no_match_vars }; |
|
|
28 |
use File::Copy qw( copy move ); |
| 29 |
use File::Slurp qw( read_file ); |
| 26 |
use Net::FTP; |
30 |
use Net::FTP; |
| 27 |
use Net::SFTP::Foreign; |
31 |
use Net::SFTP::Foreign; |
| 28 |
use File::Slurp qw( read_file ); |
32 |
|
| 29 |
use File::Copy qw( copy move ); |
|
|
| 30 |
use Koha::Database; |
33 |
use Koha::Database; |
| 31 |
use Koha::DateUtils qw( dt_from_string ); |
34 |
use Koha::DateUtils qw( dt_from_string ); |
| 32 |
use Encode qw( from_to ); |
35 |
use Koha::Encryption; |
| 33 |
|
36 |
|
| 34 |
sub new { |
37 |
sub new { |
| 35 |
my ( $class, $account_id ) = @_; |
38 |
my ( $class, $account_id ) = @_; |
|
Lines 136-142
sub sftp_download {
Link Here
|
| 136 |
my $sftp = Net::SFTP::Foreign->new( |
139 |
my $sftp = Net::SFTP::Foreign->new( |
| 137 |
host => $self->{account}->host, |
140 |
host => $self->{account}->host, |
| 138 |
user => $self->{account}->username, |
141 |
user => $self->{account}->username, |
| 139 |
password => $self->{account}->password, |
142 |
password => Koha::Encryption->new->decrypt_hex($self->{account}->password), |
| 140 |
timeout => 10, |
143 |
timeout => 10, |
| 141 |
); |
144 |
); |
| 142 |
if ( $sftp->error ) { |
145 |
if ( $sftp->error ) { |
|
Lines 221-227
sub ftp_download {
Link Here
|
| 221 |
) |
224 |
) |
| 222 |
or return $self->_abort_download( undef, |
225 |
or return $self->_abort_download( undef, |
| 223 |
"Cannot connect to $self->{account}->host: $EVAL_ERROR" ); |
226 |
"Cannot connect to $self->{account}->host: $EVAL_ERROR" ); |
| 224 |
$ftp->login( $self->{account}->username, $self->{account}->password ) |
227 |
$ftp->login( $self->{account}->username, Koha::Encryption->new->decrypt_hex($self->{account}->password) ) |
| 225 |
or return $self->_abort_download( $ftp, "Cannot login: $ftp->message()" ); |
228 |
or return $self->_abort_download( $ftp, "Cannot login: $ftp->message()" ); |
| 226 |
$ftp->cwd( $self->{account}->download_directory ) |
229 |
$ftp->cwd( $self->{account}->download_directory ) |
| 227 |
or return $self->_abort_download( $ftp, |
230 |
or return $self->_abort_download( $ftp, |
|
Lines 262-268
sub ftp_upload {
Link Here
|
| 262 |
) |
265 |
) |
| 263 |
or return $self->_abort_download( undef, |
266 |
or return $self->_abort_download( undef, |
| 264 |
"Cannot connect to $self->{account}->host: $EVAL_ERROR" ); |
267 |
"Cannot connect to $self->{account}->host: $EVAL_ERROR" ); |
| 265 |
$ftp->login( $self->{account}->username, $self->{account}->password ) |
268 |
$ftp->login( $self->{account}->username, Koha::Encryption->new->decrypt_hex($self->{account}->password) ) |
| 266 |
or return $self->_abort_download( $ftp, "Cannot login: $ftp->message()" ); |
269 |
or return $self->_abort_download( $ftp, "Cannot login: $ftp->message()" ); |
| 267 |
$ftp->cwd( $self->{account}->upload_directory ) |
270 |
$ftp->cwd( $self->{account}->upload_directory ) |
| 268 |
or return $self->_abort_download( $ftp, |
271 |
or return $self->_abort_download( $ftp, |
|
Lines 293-299
sub sftp_upload {
Link Here
|
| 293 |
my $sftp = Net::SFTP::Foreign->new( |
296 |
my $sftp = Net::SFTP::Foreign->new( |
| 294 |
host => $self->{account}->host, |
297 |
host => $self->{account}->host, |
| 295 |
user => $self->{account}->username, |
298 |
user => $self->{account}->username, |
| 296 |
password => $self->{account}->password, |
299 |
password => Koha::Encryption->new->decrypt_hex($self->{account}->password), |
| 297 |
timeout => 10, |
300 |
timeout => 10, |
| 298 |
); |
301 |
); |
| 299 |
$sftp->die_on_error("Cannot ssh to $self->{account}->host"); |
302 |
$sftp->die_on_error("Cannot ssh to $self->{account}->host"); |