/usr/share/perl5/Shutter/Upload/FTP.pm is in shutter 0.94-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | ###################################################
#
# Copyright (C) 2008-2013 Mario Kemper <mario.kemper@gmail.com>
#
# This file is part of Shutter.
#
# Shutter is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Shutter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Shutter; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
###################################################
package Shutter::Upload::FTP;
use utf8;
use strict;
use Net::FTP;
use URI;
use URI::Split qw(uri_split);
#Glib
use Glib qw/TRUE FALSE/;
#--------------------------------------
sub new {
my $class = shift;
my $self = {
_debug_cparam => shift,
_shutter_root => shift,
_gettext_object => shift,
_main_gtk_window => shift,
_mode => shift #active or passive
};
#connection settings
$self->{_prot} = "";
$self->{_host} = "";
$self->{_port} = "";
$self->{_path} = "";
$self->{_auth} = "";
$self->{_query} = "";
$self->{_frag} = "";
#credentials and filename
$self->{_filename} = undef;
$self->{_username} = undef;
$self->{_password} = undef;
bless $self, $class;
return $self;
}
sub login {
my ( $self, $uri, $username, $password ) = @_;
#uri should start with ftp:// to parse it correctly
$uri = "ftp://" . $uri unless ( $uri =~ /^ftp:\/\// );
#split uri
my $u = URI->new($uri);
( $self->{_prot}, $self->{_auth}, $self->{_path}, $self->{_query}, $self->{_frage} )
= uri_split($u);
#get port and host
$self->{_auth} =~ /(.*):?([0-9]?)/;
$self->{_host} = $1 || "undefined.host";
$self->{_port} = $2 || 21;
#check uri and return if anything is missing
unless ( $self->{_host} && $self->{_port} ) {
return (
$self->{_gettext_object}->get("Illegal URI."),
"<<ftp://host:port/path>>",
undef);
}
#store parms as object vars
$self->{_username} = $username;
$self->{_password} = $password;
utf8::encode $self->{_host};
utf8::encode $self->{_username} if $self->{_username};
utf8::encode $self->{_password} if $self->{_password};
#CONNECT TO FTP SERVER
$self->{_ftp} = Net::FTP->new(
$self->{_host},
Passive => $self->{_mode},
Port => $self->{_port},
Timeout => 10
)
or return (
$self->{_gettext_object}->get("Connection error."),
$self->{_gettext_object}->get("Please check your connectivity and try again."),
$@);
#TRY TO LOGIN WITH GIVEN CREDENTIALS
$self->{_ftp}->login( $self->{_username}, $self->{_password} )
or return (
sprintf ($self->{_gettext_object}->get("Login with username %s failed."), "'".$self->{_username}."'"),
$self->{_gettext_object}->get("Please check your credentials and try again."),
$self->{_ftp}->message);
#THERE ARE NO ERRORS WHEN ROUTINE RETURNS AT THIS POINT
return (FALSE);
}
sub upload {
my ( $self, $upload_filename ) = @_;
#store parms as object vars
$self->{_filename} = $upload_filename;
utf8::encode $self->{_filename};
#CHANGE WORKING DIRECTORY USING CWD COMMAND
$self->{_ftp}->cwd( $self->{_path} )
or return (
$self->{_gettext_object}->get("Failed"),
$self->{_gettext_object}->get("Cannot change working directory."),
$self->{_ftp}->message
);
$self->{_ftp}->binary;
#UPLOAD FILE
$self->{_ftp}->put( $self->{_filename} )
or return (
$self->{_gettext_object}->get("Failed"),
$self->{_gettext_object}->get("Command 'put' failed."),
$self->{_ftp}->message
);
#THERE ARE NO ERRORS WHEN ROUTINE RETURNS AT THIS POINT
return (FALSE);
}
sub quit {
my $self = shift;
#QUIT CONNECTION
$self->{_ftp}->quit;
#THERE ARE NO ERRORS WHEN ROUTINE RETURNS AT THIS POINT
return (FALSE);
}
1;
|