File transfer using sftp¶
Learning outcomes
- Practice using the documentation of your favorite HPC cluster
- (Optional) Can transfer files using
sftp
For teachers
Teaching goals are:
- Learners have practiced using the documentation of their favorite HPC cluster
- Learners have transferred files using
sftp
Prior questions:
- Who has heard of
sftp? - Who has already used
sftp?
Introduction¶
SFTP is an abbreviation of 'SSH File Transfer Protocol' and 'SSH' is an abbreviation of 'Secure Shell protocol'.
- The difference from
rsyncandscpis that you login to a SFTP session- just like a log in to a server with SSH.
- You use the terminal to transfer the files.
- You need the credentials only when establishing the connection.
Pros
- Secure
- Use cases:
- copying large or many files
- asks if you want to overwrite target files
- possible to resume file transfer after a broken connection.
- handle bulk file transfers
- modify directories
- and encrypt or decrypt specific files
When not to use
- Rsync is better for "syncing"
Procedure¶
- Run the sftp commands on YOUR computer, since you probably do not have a server address to your computer!
- In the terminal (from local, not server session)
In sftp session, go to right folders and upload/download files to/from the server. You can do this as long as the connection is active!
pwd/cd/ls- browse and list files in server file systemlpwd/lcd/lls- browse and list files in local file systemput <file/folder>- Copy a file/folder from the local computer to the remote hostget <file/folder>- Copy a file/folder from the remote host to the local computer
Syntax for command arguments
- We use
<content>to tell that this should be replaced by applicable names or paths etcetera... - We use
[content]to tell that this argument is not necessary - Run the sftp commands on YOUR computer, since you probably do not have a server address to your computer!
Example for Tetralith
Connect to SFTP session
In the terminal, run sftp to connect to Tetralith by doing:
If asked, give your center's password. You can get rid of this prompt if you have setup SSH keys
Upload/download files to/from Tetralith
In sftp session, upload/download files/folders to/from the server.
put localfile.txt- Copy a file from the local computer to the remote hostget serverfile.txt- Copy a file from the remote host to the local computer
Cheat sheet in the SFTP session
?/help- List of all commands or explain a command, eg ? get
Remote
put- Copy a file from the local computer to the remote hostcd- Change the active directory path on the remote hostdir/ls- List the contents of the current directory on the remote hostpwd- Show the present working directory path on the remote hostmkdir- Create a directory on the remote hostrename- Rename a file on the remote hostrm- Delete a file on the remote hostrmdir- Remove an empty directory on the remote hostexit/quit- Close the connection and leave SFTP
Locally
get- Copy a file from the remote host to the local computerlcd- Change the active directory on the local systemlls- List the contents of the current directory on the local computerlmkdir- Create a directory on the local computerlpwd- Show the present working directory on the local computer
Exercises¶
Exercise 0: Use the documentation of your HPC cluster
- Search for how to transfer files to/from your HPC cluster using
scp. Which URL is it described? - Tip: not all HPC centers have documented this, so you should give up searching after a while.
- If the center maintaining you HPC cluster has not documented how to use
sftp, follow the Rackham documentation.
Where is that documentation?
| HPC Cluster | Documentation |
|---|---|
| Alvis | FIX? None. |
| Berzelius | Documentation |
| Bianca | Documentation, through transit |
| COSMOS | Documentation |
| Dardel | Documentation about the similar psftp |
| Kebnekaise | Documentation |
| LUMI | Apparently not supported |
| Pelle | Documentation |
| Rackham | Documentation |
| Tetralith | Documentation |
| Vera | FIX? None. |
Dardel documentation uses psftp, what is that?
- It is just a SFTP component of the client PuTTY.
- Same commands as for SFTP.
Exercise 1: Establish the sftp connection and find the relevant folders locally and remotely
Tips
- Connect from your local terminal
- Orient yourself remotely and locally with
ls,cd,pwd,llsetc... - Where are you remotely?
- Go to the course folder where you have files
- Where are you locally?
- Go to your local folder used for the course
Answer (Tetralith example)
Locally
- Establish connection
$ sftp sm_bcarl@tetralith.nsc.liu.se
(sm_bcarl@tetralith.nsc.liu.se) Password:
(sm_bcarl@tetralith.nsc.liu.se) Verification code:
Connected to tetralith.nsc.liu.se.
- Use
pwdto find where you are remotely - Use
cdto reach relevant remote folder - Use
lpwdto find where you are locally -
Use
lcdto reach relevant local folder
Exercise 2: Upload
Tips
- (If you want to create a file in local terminal:
$ touch local_file_sftp) - Send it to an existing folder (e.g.
transfer) on Tetralith - Check on server (in sftp session) that it is there
Answer (Tetralith example)
Locally
- (If you want to create a file in local terminal:
$ touch local_file_sftp) - use the put command:
> put local_file_sftp
Check on server (in sftp session) that it is there
-
> ls ~/transfer
Exercise 3: Download
Tips
- (If you want to create a file in remote terminal:
$ touch remote_file_sftp) - Send it to an existing local folder
- Check locally (in sftp session) that it is there
Answer (Tetralith example)
On Server
- use the get command:
> get remote_file_sftp
Check locally (in sftp session) that it is there
-
> lls ~/transfer -
(or in the File explorer)
Some other tools¶
Terminal tools
- Rclone: Rclone is a command-line program to manage and sync your files on cloud storage.