App-Shotgun

 view release on metacpan or  search on metacpan

lib/App/Shotgun/Target/FTP.pm  view on Meta::CPAN

		$self->add_known_dir( shift @{ $self->_filedirs } );
		if ( defined $self->_filedirs->[0] ) {
			$self->ftp( 'mkdir', $self->_filedirs->[0] );
		} else {
			# Okay, finally done creating the entire path to the file!
			$self->process_put;
		}
	} else {
		die "(MKDIR) unknown state: " . $self->state;
	}

	return;
};

event mkdir_error => sub {
	my( $self, $code, $reply, $path ) = @_;

	$self->error( "[" . $self->name . "] MKDIR($path) error: $code $reply" );

	return;
};

event put_error => sub {
	my( $self, $code, $reply, $path ) = @_;

	$self->error( "[" . $self->name . "] XFER($path) error: $code $reply" );

	return;
};

event put_connected => sub {
	my( $self, $path ) = @_;

	# okay, we can send the first block of data!
	my $localpath = $self->file->absolute( $self->shotgun->source )->stringify;
	if ( open( my $fh, '<', $localpath ) ) {
		$self->_filefh( $fh );

		# send the first chunk
		$self->send_chunk;
	} else {
		$self->error( "[" . $self->name . "] XFER($path) error: unable to open $localpath: $!" );
	}

	return;
};

event put_flushed => sub {
	my( $self, $path ) = @_;

	# read the next chunk of data from the fh
	$self->send_chunk;

	return;
};

sub send_chunk {
	my $self = shift;

	my $buf;
	my $retval = read( $self->_filefh, $buf, 10_240 ); # TODO is 10240 ok? I lifted it from poco-ftp code
	if ( $retval ) {
		$self->ftp( 'put_data', $buf );
	} elsif ( $retval == 0 ) {
		# all done with the file
		if ( close( $self->_filefh ) ) {
			$self->ftp( 'put_close' );
		} else {
			$self->error( "[" . $self->name . "] XFER error: unable to close " . $self->file->absolute( $self->shotgun->source )->stringify . ": $!" );
		}
	} else {
		# error reading file
		$self->error( "[" . $self->name . "] XFER error: unable to read from " . $self->file->absolute( $self->shotgun->source )->stringify . ": $!" );
	}

	return;
}

event put => sub {
	my( $self, $code, $reply, $path ) = @_;

	# we're finally done with this transfer!
	$self->xferdone( $self );

	return;
};

no MooseX::POE::SweetArgs;
__PACKAGE__->meta->make_immutable;
1;


__END__
=pod

=head1 NAME

App::Shotgun::Target::FTP - App::Shotgun target for FTP servers

=head1 VERSION

version 0.001

=head1 DESCRIPTION

Implements the FTP target.

=head1 ATTRIBUTES

=head2 port

The port to connect on the server.

The default is: 21

=head2 usetls

Enable/disable TLS encryption for the connection.

The default is: false



( run in 1.277 second using v1.01-cache-2.11-cpan-ceb78f64989 )