| App-Nopaste documentation | Contained in the App-Nopaste distribution. |
App::Nopaste::Service::ssh - copies files to your server using scp
Kevin Falcone <falcone@cpan.org>
Thomas Sibley <trs@bestpractical.com>
The hostname to which you ssh. The left-hand side of the colon in the scp.
For example: sartak.org.
The path on disk for your pastes. For example: public_html/paste.
The path for URLs. For example: http://sartak.org/paste.
Octal permissions mode to set for the temporary file before uploading.
For example: 0644.
| App-Nopaste documentation | Contained in the App-Nopaste distribution. |
package App::Nopaste::Service::ssh; use strict; use warnings; use base 'App::Nopaste::Service'; use File::Temp; use File::Spec; use POSIX qw(strftime); sub run { my ($self, %args) = @_; my $server = $ENV{NOPASTE_SSH_SERVER} || return (0,"No NOPASTE_SSH_SERVER set"); my $docroot = $ENV{NOPASTE_SSH_DOCROOT} || return (0, "No NOPASTE_SSH_DOCROOT set"); my $topurl = $ENV{NOPASTE_SSH_WEBPATH} || "http://$server"; my $mode = $ENV{NOPASTE_SSH_MODE} || undef; my $date = strftime("%Y-%m-%d",localtime()); my ($ext) = defined $args{'filename'} && $args{'filename'} =~ /(\.[^.]+?)$/ ? $1 : ''; my $tmp = File::Temp->new( TEMPLATE => "${date}XXXXXXXX", SUFFIX => $ext, UNLINK => 1, ); my $filename = $tmp->filename; print $tmp $args{text} or return (0, "Can't write to tempfile $filename"); close $tmp or return (0, "Can't write to tempfile $filename"); chmod oct($mode), $filename if defined $mode; system('scp', '-pq', $filename, "$server:$docroot"); my ($volume, $dir, $file) = File::Spec->splitpath($filename); return (1, "$topurl/$file"); } 1; __END__