App-dropboxapi
view release on metacpan or search on metacpan
script/dropbox-api view on Meta::CPAN
} else {
getopts('ndvDshePp:', \%opts);
}
push @args, @ARGV;
my $dry = $opts{n};
my $delete = $opts{d};
my $verbose = $opts{v};
my $debug = $opts{D};
my $human = $opts{h};
my $printf = $opts{p};
my $public = $opts{P};
my $env_proxy = $opts{e};
my $max_depth = $opts{d};
if ($opts{s}) {
die "-s is gone.";
}
if ($command eq '-v') {
&help('version');
exit(0);
}
if ($command eq 'setup' || !-f $config_file) {
&setup();
}
# connect dropbox
my $config = decode_json($config_file->slurp);
$config->{key} or die 'please set config key.';
$config->{secret} or die 'please set config secret.';
$config->{access_token} or die 'please set config access_token.';
if ($config->{access_secret}) {
warn "Auto migration OAuth1 Token to OAuth2 token...";
my $oauth2_access_token = &token_from_oauth1($config->{key}, $config->{secret}, $config->{access_token}, $config->{access_secret});
if ($oauth2_access_token) {
delete $config->{access_secret};
$config->{access_token} = $oauth2_access_token;
$config_file->openw->print(encode_json($config));
warn "=> Suucess.";
} else {
die "please setup.";
}
}
if (my $access_level = delete $config->{access_level}) {
if ($access_level eq 'a') {
print "sandbox is gone, Are you sure you want to delete from the config the access_level? [y/n]: ";
chomp( my $y = <STDIN> );
if ($y =~ qr{ [yY] }xms) {
delete $config->{access_level};
$config_file->openw->print(encode_json($config));
warn "=> Suucess.";
} else {
die "cancelled.";
}
}
}
$ENV{HTTP_PROXY} = $ENV{http_proxy} if !$ENV{HTTP_PROXY} && $ENV{http_proxy};
$ENV{NO_PROXY} = $ENV{no_proxy} if !$ENV{NO_PROXY} && $ENV{no_proxy};
my $box = WebService::Dropbox->new($config);
$box->env_proxy if $env_proxy;
my $strp = new DateTime::Format::Strptime( pattern => '%Y-%m-%dT%T' );
my $strpz = new DateTime::Format::Strptime( pattern => '%Y-%m-%dT%TZ' );
my $format = {
i => 'id',
n => 'name',
b => 'size',
e => 'thumb_exists', # jpg, jpeg, png, tiff, tif, gif or bmp
d => 'is_dir', # Check if .tag = "folder"
p => 'path_display',
P => 'path_lower',
s => 'format_size',
t => 'server_modified',
c => 'client_modified', # For files, this is the modification time set by the desktop client when the file was added to Dropbox.
r => 'rev', # A unique identifier for the current revision of a file. This field is the same rev as elsewhere in the API and can be used to detect changes and avoid conflicts.
R => 'rev',
};
# ProgressBar
my $cols = 50;
if ($verbose) {
eval {
my $stty = `stty -a 2>/dev/null`;
if ($stty =~ m|columns (\d+)| || $stty =~ m|(\d+) columns|) {
$cols = $1;
}
};
}
my $exit_code = 0;
if ($command eq 'ls' or $command eq 'list') {
&list(@args);
} elsif ($command eq 'find') {
&find(@args);
} elsif ($command eq 'du') {
&du(@args);
} elsif ($command eq 'copy' or $command eq 'cp') {
©(@args);
} elsif ($command eq 'move' or $command eq 'mv') {
&move(@args);
} elsif ($command eq 'mkdir' or $command eq 'mkpath') {
&mkdir(@args);
} elsif ($command eq 'delete' or $command eq 'rm' or $command eq 'rmtree') {
&delete(@args);
} elsif ($command eq 'upload' or $command eq 'up' or $command eq 'put') {
&upload(@args);
} elsif ($command eq 'download' or $command eq 'dl' or $command eq 'get') {
&download(@args);
} elsif ($command eq 'sync') {
&sync(@args);
} elsif ($command eq 'help' or (not length $command)) {
&help(@args);
} else {
die "unknown command $command";
script/dropbox-api view on Meta::CPAN
Name
dropbox-api-get - download file
SYNOPSIS
dropbox-api get dropbox:<dropbox_file> <file>
Example
dropbox-api get dropbox:/Public/product/dropbox-api/README.md README.md
};
} elsif ($command eq 'sync') {
$help = q{
Name
dropbox-api-sync - sync directory
SYNOPSIS
dropbox-api sync dropbox:<source_dir> <target_dir> [options]
dropbox-api sync <source_dir> dropbox:<target_dir> [options]
Example
dropbox-api sync dropbox:/Public/product/dropbox-api/ ~/work/dropbox-api/
dropbox-api sync ~/work/dropbox-api/ dropbox:/Public/product/dropbox-api/ -vdn
dropbox-api sync ~/work/dropbox-api/ dropbox:/Public/product/dropbox-api/ -d
Options
-v increase verbosity
-n show what would have been transferred (dry-run)
-d delete files that don't exist on sender
};
} elsif ($command eq 'version') {
$help = qq{
This is dropbox-api-command, version $VERSION
Copyright 2016, Shinichiro Aska
Released under the MIT license.
Documentation
this system using "dropbox-api help".
If you have access to the Internet, point your browser at
https://github.com/s-aska/dropbox-api-command,
the dropbox-api-command Repository.
};
} else {
$help = qq{
Usage: dropbox-api <command> [args] [options]
Available commands:
setup get access_key and access_secret
ls list directory contents
find walk a file hierarchy
du disk usage statistics
cp copy file or directory
mv move file or directory
mkdir make directory (Create intermediate directories as required)
rm remove file or directory (Attempt to remove the file hierarchy rooted in each file argument)
put upload file
get download file
sync sync directory (local => dropbox or dropbox => local)
Common Options
-e enable env_proxy ( HTTP_PROXY, NO_PROXY )
-D enable debug
-v verbose
See 'dropbox-api help <command>' for more information on a specific command.
};
}
$help =~ s|^ {8}||mg;
$help =~ s|^\s*\n||;
print "\n$help\n";
}
sub setup {
my $config = {};
print "Please Input API Key: ";
chomp( my $key = <STDIN> );
die 'Get API Key from https://www.dropbox.com/developers' unless $key;
$config->{key} = $key;
print "Please Input API Secret: ";
chomp( my $secret = <STDIN> );
die 'Get API Secret from https://www.dropbox.com/developers' unless $secret;
$config->{secret} = $secret;
my $box = WebService::Dropbox->new($config);
$box->env_proxy if $env_proxy;
my $login_link = $box->authorize;
die $box->error if $box->error;
print "1. Open the Login URL: $login_link\n";
print "2. Input code and press Enter: ";
chomp( my $code = <STDIN> );
unless ($box->token($code)) {
die $box->error;
}
$config->{access_token} = $box->access_token;
print "success! try\n";
print "> dropbox-api ls\n";
print "> dropbox-api find /\n";
$config_file->openw->print(encode_json($config));
chmod 0600, $config_file;
exit(0);
}
sub du {
my $remote_base = decode('locale_fs', slash(shift));
$remote_base =~ s|/$||;
my $entries = _find($remote_base);
my $dir_map = {};
for my $content (@{ $entries }) {
if ($content->{'.tag'} eq 'folder') {
next;
}
my @paths = _paths($remote_base, $content->{path_lower});
for my $path (@paths) {
$dir_map->{ lc $path } ||= 0;
$dir_map->{ lc $path } += $content->{size};
( run in 0.393 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )