How to Transfer Data at the Command Line
There are two main command-line SSH commands to transfer files: scp and sftp. scp is a non-interactive command that takes a set of files to copy on the command line, copies them, and exits. sftp is an interactive command that opens a persistent connection through which multiple copying commands can be performed.
scp
To copy one or more local files up to the Roar server, the scp syntax would be:
scp local_file <username>@datamgr.aci.ics.psu.edu:<target_directory>
The default port for scp is set to 22. If you use this port you will be automatically directed to Duo Push authentication during 2FA.
For user abc123 to copy the local files foo.c and foo.h into their home directory on the host aci-b.aci.ics.psu.edu, the following command would be used:
[abc123@local ~]$ scp foo.c foo.h abc123@datamgr.aci.ics.psu.edu:~/.
The -r (recursive) flag can be used to transfer directories.
[abc123@local ~]$ scp -r dirA abc123@datamgr.aci.ics.psu.edu:~/.
Users can also copy files from Roar onto their own computer using
[abc123@local ~]$ scp abc123@datamgr.aci.ics.psu.edu:~/fileA .
sftp
sftp is an interactive command that uses the same syntax as a standard command-line ftp client. It differs from a standard ftp client in that the authentication and the data transfer happen through the SSH protocol rather than the FTP protocol. The SSH protocol is encrypted whereas the FTP protocol is not.
There are a number of basic commands that are used inside of stfp:
- put filename: uploads the file filename
- get filename: downloads the file filename
- ls: lists the contents of the current remote directory
- lls: lists the contents of the current local directory
- pwd: returns the current remote directory
- lpwd: returns the current local directory
- cd directory: changes the current remote directory to directory
- lcd directory: changes the current local directory to directory
- The syntax for calling sftp is:
sftp username@hostname
To choose between different options for 2FA you have to set the port to 1022 using P flag similar to ssh.
An example sftp session, with both the inputs and outputs, would be:
[abc123@local ~]$ sftp abc123@submit.aci.ics.psu.edu Connecting to submit.aci.ics.psu.edu... Password: <user abc123 password> # Duo Push authentication Connected to aci-b.aci.ics.psu.edu. sftp> pwd Remote working directory: /storage/home/abc123 sftp> lpwd Local working directory: /home/abc123 sftp> cd work/depot sftp> pwd Remote working directory: /storage/work/abc123/depot sftp> lcd results sftp> lpwd Local working directory: /home/abc123/results sftp> ls -l -rw-r--r-- 1 root root 5 Mar 3 12:08 dump sftp> lls -l total 0 sftp> get dump Fetching /storage/work/abc123/depot/dump to dump /storage/work/abc123/depot/dump 100% 5 0.0KB/s 0.0KB/s 00:00 sftp> lls -l total 4 -rw-r--r-- 1 abc123 abc123 5 Mar 3 12:09 dump sftp> put data.txt Uploading data.txt to /storage/work/abc123/depot/data.txt data.txt 100% 15 0.0KB/s sftp>