SFTP and SSH into Docker Instance
SFTP replaces FTP and FTP/S. Now included in most SSH clients SFTP is the best way forward when an interactive remote file client is needed.
In this article we'll be covering how to use SFTP with a EnterMedia Database Docker instance.
1. Secure SSH access to the Docker Instance
Depending on your configuration, we may need to use either password or key based authentication for SSH access. If you have already configured password authentication the skip this section. We highly recommend using SSH keys to remotely access machines!
We have an entire article and a convienient script to obtain SSH keys for a EMDB Instance. Please follow the instructions here.
2. Connecting to the Instance
You can create an alternate config file for the connection and use the
-F switch to tell ssh to use it. Create a config file e.g. ~/.ssh/config.sftp with the contents:
Host remote.host Hostname example.com User RemoteUserName IdentityFile /path/to/alternate/ssh-key
NOTE: The man page for ssh_config expands with more info on the usage of the alternate config file
Afterwards connecting via SFTP is as simple as:
If not, then using a command similar to this will do the trick:
sftp -i /path/to/private/keyfile email@example.com
Once connected standard SFTP commands can be executed like get, or put. Here are a couple of examples to get a file or directory from the remote server to the local machine.
get -r /Some/Directory
put -r /Local/Directory
There are more commands and options to expand SFTP's operational capabilities that can also include simple file or directory modifications. The last command that should run is exit, this closes the SFTP session.
3. Exporting an Entermedia Instance's Data
If rsync isn't an option to export data, then SFTP is the second best option at hand. It's relatively simple to copy an Instance's data with the following instructions. Take in mind that rsync has a more robust file transfer than sftp, since it hashes the file to make sure the file was transfered corectly.
First, lets SFTP into the Instance, and then use the following command to preserve file structures and permissions.
get -Rpaf /opt/entermediadb/webapp/WEB-INF/data /local/path/
Here we are using the the following options:
-a flag attempts to resume partial transfers of existing files. -f If this flag is specified, then fsync will be called after the file transfer has completed to flush the file to disk. -p flag specifies that full file permissions and access times are copied too. -R flag specifies that directories will be copied recursively.
More information on SFTP's options can be found on the official manual page here.