acd_cli documentation

Version 0.3.1

Contents:

Setting up acd_cli

Check which Python 3 version is installed on your system, e.g. by running

python3 -V

If it is Python 3.2.3, 3.3.0 or 3.3.1, you need to upgrade to a higher minor version.

You may now proceed to install using PIP, your Arch package manager or build Debian/RedHat packages.

Installation with PIP

If you are new to Python, worried about dependencies or about possibly messing up your system, create and activate virtualenv like so:

cd /parent/path/to/your/new/virtualenv
virtualenv acdcli
source acdcli/bin/activate

You are now safe to install and test acd_cli. When you are finished, the environment can be disabled by simply closing your shell or running deactivate.

Please check which pip command is appropriate for Python 3 packages in your environment. I will be using ‘pip3’ as superuser in the examples.

The recommended and most up-to-date way is to directly install the master branch from GitHub.

pip3 install --upgrade git+https://github.com/yadayada/acd_cli.git

The easiest way is to directly install from PyPI.

pip3 install --upgrade --pre acdcli

PIP Errors

A version incompatibility may arise with PIP when upgrading the requests package. PIP will throw the following error:

ImportError: cannot import name 'IncompleteRead'

Run these commands to fix it:

apt-get remove python3-pip
easy_install3 pip

This will remove the distribution’s pip3 package and replace it with a version that is compatible with the newer requests package.

Installation on Arch/Debian/RedHat

Arch Linux

There are two packages for Arch Linux in the AUR, acd_cli-git, which is linked to the master branch of the GitHub repository, and acd_cli, which is linked to the PyPI release.

Building deb/rpm packages

You will need to have fpm installed to build packages.

There is a Makefile that includes commands to build Debian packages (make deb) or RedHat packages (make rpm). It will also build the required requests-toolbelt package. fpm may also be able to build packages for other distributions or operating systems.

Environment Variables

Cache Path and Settings Path

You will find the current path settings in the output of acd_cli -v init.

The cache path is where acd_cli stores OAuth data, the node cache, logs etc. You may override the cache path by setting the ACD_CLI_CACHE_PATH environment variable.

Proxy support

Requests supports HTTP(S) proxies via environment variables. Since all connections to Amazon Cloud Drive are using HTTPS, you need to set the variable HTTPS_PROXY. The following example shows how to do that in a bash-compatible environment.

export HTTPS_PROXY="https://user:pass@1.2.3.4:8080/"

Locale

If you need non-ASCII file/directory names, please check that your system’s locale is set correctly.

Dependencies

FUSE

For the mounting feature, fuse >= 2.6 is needed according to fusepy. On a Debian-based distribution, the package should be named simply ‘fuse’.

Python Packages

Under normal circumstances, it should not be necessary to install the dependencies manually.

Recommended packages are not strictly necessary; but they will be preferred to workarounds (in the case of dateutils) and bundled modules (requests-toolbelt).

If you want to the dependencies using your distribution’s packaging system and are using a distro based on Debian ‘jessie’, the necessary packages are python3-appdirs python3-colorama python3-dateutil python3-requests python3-sqlalchemy.

Uninstalling

Please run acd_cli delete-everything first to delete your authentication and node data in the cache path. Then, use pip to uninstall

pip3 uninstall acdcli

Then, revoke the permission for acd_cli_oa to access your cloud drive in your Amazon profile, more precisely at https://www.amazon.com/ap/adam.

Authorization

Before you can use the program, you will have to complete the OAuth procedure with Amazon. There is a fast and simple way and a secure way.

Simple (Appspot)

You will not have to prepare anything to initiate this authorization method, just run, for example, acd_cli init.

A browser (tab) will open and you will be asked to log into your Amazon account or grant access for ‘acd_cli_oa’. Signing in or clicking on ‘Continue’ will download a JSON file named oauth_data, which must be placed in the cache directory displayed on screen (e.g. /home/<USER>/.cache/acd_cli).

You may view the source code of the Appspot app that is used to handle the server part of the OAuth procedure at https://tensile-runway-92512.appspot.com/src.

Advanced Users (Security Profile)

You must create a security profile and have it whitelisted. Have a look at Amazon’s ACD getting started guide. Select all permissions for your security profile and add a redirect URL to http://localhost.

Put your own security profile data in a file called client_data in the cache directory and have it adhere to the following form.

{
    "CLIENT_ID": "amzn1.application-oa2-client.0123456789abcdef0123456789abcdef",
    "CLIENT_SECRET": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
}

You may now run acd_cli -v init. The authentication procedure is similar to the one above. A browser (tab) will be opened and you will be asked to log in. Unless you have a local webserver running on port 80, you will be redirected to your browser’s error page. Just copy the URL (e.g. http://localhost/?code=AbCdEfGhIjKlMnOpQrSt&scope=clouddrive%3Aread_all+clouddrive%3Awrite) into the console.

Changing authorization methods

If you want to change between authorization methods, go to your cache path (it is stated in the output of acd_cli -v init) and delete the file oauth_data and, if it exists, client_data.

Usage

acd_cli may be invoked as acd_cli or acdcli.

Most actions need the node cache to be initialized and up-to-date, so please run a sync. A sync will fetch the changes since the last sync or the full node list if the cache is empty.

The following actions are built in

sync (s)            refresh node list cache; necessary for many actions
clear-cache (cc)    clear node cache [offline operation]

tree (t)            print directory tree [offline operation]
children (ls)       list a folder's children [offline operation]

find (f)            find nodes by name [offline operation] [case insensitive]
find-md5 (fm)       find files by MD5 hash [offline operation]
find-regex (fr)     find nodes by regular expression [offline operation] [case insensitive]

upload (ul)         file and directory upload to a remote destination
overwrite (ov)      overwrite file A [remote] with content of file B [local]
stream (st)         upload the standard input stream to a file
download (dl)       download a remote folder or file; will skip existing local files
cat                 output a file to the standard output stream

create (c, mkdir)   create folder using an absolute path

list-trash (lt)     list trashed nodes [offline operation]
trash (rm)          move node to trash
restore (re)        restore node from trash

move (mv)           move node A into folder B
rename (rn)         rename a node

resolve (rs)        resolve a path to a node ID [offline operation]

usage (u)           show drive usage data
quota (q)           show drive quota [raw JSON]
metadata (m)        print a node's metadata [raw JSON]

mount               mount the cloud drive at a local directory
umount              unmount cloud drive(s)

Please run acd_cli --help to get a current list of the available actions. A list of further arguments of an action and their order can be printed by calling acd_cli [action] --help.

Most node arguments may be specified as a 22 character ID or a UNIX-style path. Trashed nodes’ paths might not be able to be resolved correctly; use their ID instead.

There are more detailed instructions for file transfer actions, find actions and FUSE documentation.

Logs will automatically be saved into the cache directory.

Global Flags/Parameters

--verbose (-v) and --debug (-d) will print additional messages to standard error.

--no-log (-nl) will disable the automatic logging feature that saves log files to the cache directory.

--color will set the coloring mode according to the specified argument (auto, never or always). Coloring is turned off by default; it is used for file/folder listings.

--check (-c) sets the start-up database integrity check mode. The default is to perform a full check. Setting the check to quick or none may speed up the initialization for large databases.

--utf (-u) will force the output to be encoded in UTF-8, regardless of the system’s settings.

Exit Status

When the script is done running, its exit status can be checked for flags. If no error occurs, the exit status will be 0. Possible flag values are:

flag value
general error 1
argument error 2
failed file transfer 8
upload timeout 16
hash mismatch 32
error creating folder 64
file size mismatch 128
cache outdated 256
remote duplicate 512
duplicate inode 1024
file/folder name collision 2048

If multiple errors occur, their values will be compounded by a binary OR operation.

File transfer

acd_cli offers multi-file transfer actions - upload and download - and single-file transfer actions - overwrite, stream and cat.

Multi-file transfers can be done with concurrent connections by specifying the argument -x NUM. If remote folder hierarchies or local directory hierarchies need to be created, this will be done prior to the file transfers.

Actions

upload

The upload action will upload files or recursively upload directories. Existing files will not be changed, normally.

Syntax:

acdcli upload /local/path [/local/next_path [...]] /remote/path

If the --overwrite (-o) argument is specified, a remote file will be updated if a) the local file’s modification time is higher or b) the local file’s creation time is higher and the file size is different. The --force (-f) argument can be used to force overwrite.

overwrite

The upload action overwrites the content of a remote file with a local file.

Syntax:

acdcli overwrite /local/path /remote/path

download

The download action can download a single file or recursively download a directory. If a file already exists locally, it will not be overwritten.

Syntax:

acdcli download /remote/path [/local/path]

If the local path is omitted, the destination path will be the current working directory.

stream

This action will upload the standard input stream to a file.

Syntax:

some_process | acdcli stream file_name /remote/path

cat

This action outputs the content of a file to standard output.

Abort/Resume

Incomplete file downloads will be resumed automatically. Aborted file uploads are not resumable at the moment.

Folder or directory hierarchies that were created for a transfer do not need to be recreated when resuming a transfer.

Retry

Failed upload, download and overwrite actions allow retries on error by specifying the --max-retries|-r argument, e.g. acd_cli <ACTION> -r MAX_RETRIES.

Exclusion

Files may be excluded from upload or download by regex on their name or by file ending. Additionally, paths can be excluded from upload. Regexes and file endings are case-insensitive.

It is possible to specify multiple exclusion arguments of the same kind.

Deduplication

Server-side deduplication prevents completely uploaded files from being saved as a node if another file with the same MD5 checksum already exists. acd_cli can prevent uploading duplicates by checking local files’ sizes and MD5s. Empty files are never regarded duplicates.

Finding nodes

The find actions will search for normal (active) and trashed nodes and list them.

find

The find action will perform a case-insensitive search for files and folders that include the name or name segment given as argument, so e.g. acdcli find foo will find “foo” , “Foobar”, etc.

find-md5

find-md5 will search for files that match the MD5 hash given. The location of a local file may be determined like so:

acdcli find-md5 `md5sum local/file | cut -d" " -f1`

find-regex

find-regex searches for the specified regex in nodes’ names.

FUSE module

Status

The FUSE support is still in its early stage and may be (prone to bugs). acd_cli’s FUSE module has the following filesystem features implemented:

Feature Working
Basic operations
List directory
Read
Write [1]
Rename
Move
Trashing
OS-level trashing [2]
View trash
Misc
Automatic sync
ctime/mtime update
Custom permissions
Hard links partially [3]
Symbolic links [4]
[1]partial writes are not possible (i.e. writes at random offsets)
[2]restoring might not work
[3]manually created hard links will be displayed, but it is discouraged to use them
[4]soft links are not part of the ACD API

Usage

The command to mount the (root of the) cloud drive to the empty directory path/to/mountpoint is

acd_cli mount path/to/mountpoint

A cloud drive folder may be mounted similarly, by

acd_cli mount --modules="subdir=/folder" path/to/mountpoint

Unmounting is usually achieved by the following command

fusermount -u path/to/mountpoint

If the mount is busy, the --lazy (-z) flag can be used. There exists a convenience action acd_cli umount that unmounts all ACDFuse mounts.

Mount options

For further information on the most of the options below, see your mount.fuse man page.

To convert the node’s standard character set (UTF-8) to the system locale, the modules argument may be used, e.g. --modules="iconv,to_code=CHARSET".

--allow-other, -ao
 allow all users to access the mountpoint (may need extra configuration)
--allow-root, -ar
 allow the root user to access the mountpoint (may need extra configuration)
--foreground, -fg
 do not detach process until filesystem is destroyed (blocks)
--interval INT, -i INT
 set the node cache sync (refresh) interval to INT seconds
--nlinks, -n calculate the number of links for folders (slower)
--nonempty, -ne
 allow mounting to a non-empty mount point
--read-only, -ro
 disallow write operations (does not affect cache refresh)
--single-threaded, -st
 disallow multi-threaded FUSE operations

Library Path

If you want or need to override the standard libfuse path, you may set the environment variable LIBFUSE_PATH to the full path of libfuse, e.g.

export LIBFUSE_PATH="/lib/x86_64-linux-gnu/libfuse.so.2"

This is particularly helpful if the libfuse library is properly installed, but not found.

Logging

For debugging purposes, the recommended command to run is

acd_cli -d mount -i0 -fg path/to/mountpoint

That command will disable the automatic refresh (i.e. sync) of the node cache (-i0) and disable detaching from the console.

Contributing guidelines

Using the Issue Tracker

The issue tracker is not a forum! This does not mean there is no need for good etiquette, but that you should not post unnecessary information. Each reply will cause a notification to be sent to all of the issue’s participants and some of them might consider it spam.

For minor corrections or additions, try to update your posts rather than writing a new reply. Use strike-through markdown for corrections and put updates at the bottom of your original post.

+1ing an issue or “me, too” replies will not get anything done faster.

Adding Issues

If you have a question, please read the documentation and search the issue tracker. Read the documentation again. If you still have a question, please consider using the (Gitter chat <httpsd//gitter.im/yadayada/acd_cli>(_ or sending an e-mail to (acd_cli@mail.com <mailtodacd_cli@mail.com>(_ instead of opening an issue.

If you absolutely must open an issue, check that you are using the latest master commit and there is no existing issue that fits your problem (including closed and unresolved issues). Try to reproduce the issue on another machine or ideally on another operating system, if possible.

Please provide as much possibly relevant information as you can. This should at least containd

  • your operating system and Python version, e.g. as determined by dcoded(python3 -c ‘import platform as p; print(p.python_version()); print(p.platform())’(
  • the command/s you used
  • what happened
  • what you think should have happened instead (and maybe give a reason)

You might find the ((–verbose(( and, to a lesser extent, ((–debug(( flags helpful.

Use (code block markup <httpsd//guides.github.com/features/mastering-markdown/>(_ for console output, log messages, etc.

Code

There are no real programming guidelines as of yet. Please use function annotations for typing like specified in PEP 3107 and, to stay 3.2-compliant, stringified PEP 484 type hints where appropriate. The limit on line length is 100 characters.

It is a generally a good idea to explicitly announce that you are working on an issue.

Please squash your commits and add yourself to the (contributors list <docs/contributors.rst>(_ before making a pull request.

Have a look at (Github’s general guide how to contribute <httpsd//guides.github.com/activities/contributing-to-open-source/#contributing>(_. It’s not necessary to create a feature branch, i.e. you may commit to the master branch.

There is also a (TODO <docs/TODO.rst>(_ list of some of the open tasks.

Donations

You might also want to consider (making a donation <httpsd//www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V4V4HVSAH4VW8>(_ to further the development of acd_cli.

Contributors

Thanks to

Also thanks to

  • fibersnet for pointing out a possible deadlock in ACDFuse.
  • and everyone else who I forgot to mention

TODO

General / API

  • switch to multiprocessing (?)
  • metalink support (?)

API

  • support of node labels
  • support for assets (?)
  • favorite support (feature not yet announced officially)
  • rip out the Appspot authentication handler

CLI

  • unify the find action
  • check symlink behavior for different Python versions (#95)

FUSE

  • invalidate chunks of StreamedResponseCache (implement a time-out)
  • respect flags when opening files
  • implement flush
  • use a filesystem test suite

File Transfer

  • more sophisticated progress handler that supports offsets
  • copy local mtime on upload (#58)
  • add path exclusion by argument for download
  • piped overwrite

User experience

  • shell completion for remote directories
  • even nicer help formatting
  • log coloring

Tests

  • cache methods
  • more functional tests
  • fuse module

Documentation

  • write how-to on packaging plugins (sample setup.py)

Ancient History

0.1.3

  • plugin mechanism added
  • OAuth now via Appspot; security profile no longer necessary
  • back-off algorithm for API requests implemented

0.1.2

new:
  • overwriting of files
  • recursive upload/download
  • hashing of downloaded files
  • clear-cache action
fixes:
  • remove-child accepted status code
  • fix for upload of files with Unicode characters
other:
  • changed database schema

acd_cli provides a command line interface to Amazon Cloud Drive and allows mounting your cloud drive using FUSE for read and write access. It is currently in beta stage.

Node Cache Features

  • caching of local node metadata in an SQLite database
  • addressing of remote nodes via a pathname (e.g. ((/Photos/kitten.jpg(()
  • file search

CLI Features

  • tree or flat listing of files and folders
  • simultaneous uploads/downloads, retry on error
  • basic plugin support

File Operations

  • upload/download of single files and directories
  • streamed upload/download
  • folder creation
  • trashing/restoring
  • moving/renaming nodes

Documentation

The full documentation is available at (<httpsd//acd-cli.readthedocs.org>(_.

Quick Start

Have a look at the (known issues(_, then follow the (setup guide <docs/setup.rst>(_ and (authorize <docs/authorization.rst>(_. You may then use the program as described in the (usage guide <docs/usage.rst>(_.

CLI Usage Example

In this example, a two-level folder hierarchy is created in an empty cloud drive. Then, a relative local path ((local/spam(( is uploaded recursively using two connections. dd

$ acd_cli sync
Syncing... Done.
$ acd_cli ls /
[PHwiEv53QOKoGFGqYNl8pw] [A] /

$ acd_cli mkdir /egg/ $ acd_cli mkdir /egg/bacon/

$ acd_cli upload -x 2 local/spam/ /egg/bacon/
[################################] 100.0% of 100MiB 12/12 654.4KB/s
$ acd_cli tree
/
egg/
bacon/
spam/
sausage spam

[...]

The standard node listing format includes the node ID, the first letter of its status and its full path. Possible statuses are “AVAILABLE” and “TRASH”.

Known Issues

It is not possible to upload files using Python 3.2.3, 3.3.0 and 3.3.1 due to a bug in the http.client module.

If you encounter Unicode problems, check that your locale is set correctly or use the ((–utf(( argument to force the script to use UTF-8 output encoding. Windows users may try to execute the provided reg file (assets/win_codepage.reg), tested with Windows 8.1, to set the command line interface encoding to cp65001.

API Restrictions

  • the current upload file size limit is 50GiB
  • uploads of large files >10 GiB may be successful, yet a timeout error is displayed (please check the upload by syncing manually)
  • storage of node names is case-preserving, but not case-sensitive (this should not concern Apple users)
  • it is not possible to share or delete files

Contribute

Have a look at the (contributing guidelines <CONTRIBUTING.rst>(_.

Recent Changes

0.3.1

  • general improvements for FUSE
  • FUSE write support added
  • added automatic logging
  • sphinx documentation added

0.3.0

  • FUSE read support added

0.2.2

  • sync speed-up
  • node listing format changed
  • optional node listing coloring added (for Linux or via LS_COLORS)
  • re-added possibility for local OAuth

0.2.1

  • curl dependency removed
  • added job queue, simultaneous transfers
  • retry on error

0.2.0

  • setuptools support
  • workaround for download of files larger than 10 GiB
  • automatic resuming of downloads