Back to course

File Transfer Protocols: Using scp and sftp

Termux Masterclass: From Zero to Linux Power User on Android

48. File Transfer Protocols: Using scp and sftp

When dealing with remote servers (managed via SSH), secure file transfer is essential. scp and sftp (part of the openssh package) provide secure methods.

1. Secure Copy (scp)

scp (Secure Copy) is used to copy files over an SSH connection, using syntax similar to cp.

Syntax: scp [options] [source] [destination]

Example 1: Uploading a local file to a remote server

bash

Copy local_backup.tar.gz to the user's home directory on the remote server

$ scp local_backup.tar.gz user@remote_server:/home/user/

Example 2: Downloading a file from a remote server

bash

Copy remote_data.log from the server to your current Termux directory

$ scp user@remote_server:/var/log/remote_data.log .

2. Secure File Transfer Protocol (sftp)

sftp provides an interactive shell interface that allows you to browse, upload, download, and manage files on a remote system securely, similar to using an FTP client.

bash $ sftp user@remote_server

Inside the sftp shell:

ls # List remote files lls # List local Termux files get /path/to/remote/file put local_file.txt quit

These tools are indispensable for managing projects hosted outside your Android device.