Cloud Storage and Console FTP Clients
Today, we’ll be taking an in-depth look at how to access and manage Cloud Storage from console FTP clients, which are often used for scheduling backups and archiving.
Every client has its own unique (and somewhat complicated) command syntax. To spare our users the headache and save them time while writing scripts, we’ve decided to put together a small cheat sheet with command examples for the most common operations:
- uploading files to storage;
- downloading files with the option to resume if the connection times out or gets interrupted;
- synchronizing local files with files in storage and vice versa.
LFTP
To upload a file to storage:
$ lftp -e 'cd /container/; put /path/to/local/file; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
(here, xxxx_ftp is our username and Pas$w0rD our password, /container/ is the container name, and /path/to/local/file is the path to the file on the local machine).
To upload a folder and all of its contents:
$ lftp -e 'mirror -R /path/to/local/dir/ /container/; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
(/path/to/local/dir/ indicates the path to the folder on the local machine).
When performing a repeat upload operation, the container’s contents will be synchronized with the corresponding folder on the local machine: only the files that weren’t there at the time of the last synchronization will be uploaded.
Using the -delete option, we can delete files that are no longer on the local machine from storage. This is useful for clearing outdated files from your storage.
$ lftp -e 'mirror --delete -R /path/to/local/dir/ /container/; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
To download a file from storage to your local machine:
$ lftp -e 'get /container/file -o to-dir/; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
To resume a download (for example, if your connection was interrupted or the download timed out):
$ lftp -e 'get -c /container/file -o to-dir/; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
To download a folder and its contents from storage:
$ lftp -e 'mirror /container/ to-dir/; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
Adding the -P option to the previous command lets you complete the download in multiple streams, which speeds up the overall operation:
$ lftp -e 'mirror -P 10 /container/ to-dir/; bye' -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
All of these commands can be executed in interactive mode. Interactive mode can be enabled using the command:
$ lftp -u xxxx_ftp,Pas$w0rD ftp.selcdn.ru
NCFTP
To upload a file to storage:
$ ncftpput -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru /container/ /path/to/local/file
NCFTP supports automatic repeat operations if an error occurs during execution. This is done using the -r option:
# repeat 5 times $ ncftpput -r 5 -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru /container/ /path/to/local/file
To upload a folder and all of its contents:
$ ncftpput -R -r 5 -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru /container/ /path/to/local/dir/
To synchronize local files with those in storage:
$ ncftpput -z -R -r 5 -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru /container/ /path/to/local/dir/
To download one file from storage:
ncftpget -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru to-dir/ /container/file
To resume a download, use the -z option:
$ ncftpget -z -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru to-dir /container/file
To download a folder and its contents to your local machine:
$ ncftpget -R -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru to-dir/ /container/dir/ # resume a download $ ncftpget -R -z -u xxxx_ftp -p pas$w0rD ftp.selcdn.ru to-dir /container/dir/
Wget
To download a file to your local machine:
# file will be downloaded to current folder $ wget ftp://xxxx_ftp:pas$w0rD@ftp.selcdn.ru/container/file # to resume a download $ wget -с ftp://xxxx_ftp:pas$w0rD@ftp.selcdn.ru/container/file
To download a folder and its contents to your local machine:
$ wget -r ftp://xxxx_ftp:pas$w0rD@ftp.selcdn.ru/container/dir/ # resume a download $ wget -r -с ftp://xxxx_ftp:pas$w0rD@ftp.selcdn.ru/container/dir/
cURL
To upload a file to storage:
$ curl ftp://ftp.selcdn.ru/container/ --user xxxx_ftp:pas$w0rD -T /path/to/local/file
To download a file to your local machine:
# an output filename must be specified (option -o) $ curl ftp://ftp.selcdn.ru/container/file --user xxxx_ftp:pas$w0rD -o file
SFTP Support
Our storage now supports SFTP access, although this is still in the testing phase.
We’d like to invite anyone interested to try these new options. To connect, enter sftp.selcdn.ru as the host. Please let us know about any and all errors or problems while accessing storage via SFTP. We’d be happy to hear your comments and suggestions for improving our service.