package App::FTPThis;

our $DATE = '2017-11-10'; # DATE
our $VERSION = '0.003'; # VERSION

use 5.010001;
use strict;
use warnings;

use Cwd;
use Getopt::Long;
use Pod::Usage;

sub new {
    my $class = shift;
    my $self = bless {port => 8021, root => '.'}, $class;

    GetOptions($self, "help", "man", "port=i",
           ) || pod2usage(2);
    pod2usage(1) if $self->{help};
    pod2usage(-verbose => 2) if $self->{man};

    if (@ARGV > 1) {
        pod2usage("$0: Too many roots, only single root supported");
    } elsif (@ARGV) {
        $self->{root} = shift @ARGV;
    } else {
        $self->{root} = getcwd();

    return $self;

sub run {
    require File::Slurper;
    require File::Temp;
    require Net::FTPServer::RO_FTPThis::Server;

    my ($self) = @_;

    my $dir = File::Temp::tempdir(CLEANUP => !$ENV{DEBUG});
    say "D: temporary dir = $dir" if $ENV{DEBUG};

            "root directory: $self->{root}\n",
            "allow anonymous: 1\n",
            "anonymous password check: none\n",
            "anonymous password enforce: 0\n",
            "home directory: $self->{root}\n",
            "limit memory: -1\n",
            "limit nr processes: -1\n",
            "limit nr files: -1\n",

    say "Starting FTP server on port $self->{port} ...";

    chdir $self->{root} or die "Can't chdir to $self->{root}: $!";
    local @ARGV = (
        "-p", $self->{port},
        "-s", # daemon mode (not background, which is -S)
    my $ftpd = Net::FTPServer::RO_FTPThis::Server->run;

# ABSTRACT: Export the current directory over anonymous FTP



=encoding UTF-8

=head1 NAME

App::FTPThis - Export the current directory over anonymous FTP

=head1 VERSION

This document describes version 0.003 of App::FTPThis (from Perl distribution App-FTPThis), released on 2017-11-10.


 # Not to be used directly, see ftp_this command


=head1 METHODS

=head2 new

=head2 run


=head2 DEBUG => bool

If set to true, won't cleanup temporary directory.


Please visit the project's homepage at L<>.

=head1 SOURCE

Source repository is at L<>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired

=head1 SEE ALSO

=head1 AUTHOR

perlancar <>


This software is copyright (c) 2017 by

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.