This entire document was copied from the HPC-carpentry lesson on 10-23-18 and is intended for student use.

Transferring files interactively with sftp

scp is useful, but what if we don't know the exact location of what we want to transfer? Or
perhaps we're simply not sure which files we want to transfer yet. sftp is an interactive way of
downloading and uploading files. Let's connect to a cluster, using sftp- you'll notice it works
the same way as SSH:

sftp yourUsername@remote.computer.address

{: .bash}

This will start what appears to be a bash shell (though our prompt says sftp>). However we only
have access to a limited number of commands. We can see which commands are available with help:

sftp> help

{: .bash}

Available commands:
bye                                Quit sftp
cd path                            Change remote directory to 'path'
chgrp grp path                     Change group of file 'path' to 'grp'
chmod mode path                    Change permissions of file 'path' to 'mode'
chown own path                     Change owner of file 'path' to 'own'
df [-hi] [path]                    Display statistics for current directory or
                                   filesystem containing 'path'
exit                               Quit sftp
get [-afPpRr] remote [local]       Download file
reget [-fPpRr] remote [local]      Resume download file
reput [-fPpRr] [local] remote      Resume upload file
help                               Display this help text
lcd path                           Change local directory to 'path'
lls [ls-options [path]]            Display local directory listing
lmkdir path                        Create local directory
ln [-s] oldpath newpath            Link remote file (-s for symlink)
lpwd                               Print local working directory
ls [-1afhlnrSt] [path]             Display remote directory listing

# omitted further output for clarity

{: .output}

Notice the presence of multiple commands that make mention of local and remote. We are actually
connected to two computers at once (with two working directories!).

To show our remote working directory:

sftp> pwd

{: .bash}

Remote working directory: /global/home/yourUsername

{: .output}

To show our local working directory, we add an l in front of the command:

sftp> lpwd

{: .bash}

Local working directory: /home/jeff/Documents/teaching/hpc-intro

{: .output}

The same pattern follows for all other commands:

  • ls shows the contents of our remote directory, while lls shows our local directory contents.
  • cd changes the remote directory, lcd changes the local one.

To upload a file, we type put some-file.txt (tab-completion works here).

sftp> put config.toml

{: .bash}

Uploading config.toml to /global/home/yourUsername/config.toml
config.toml                                   100%  713     2.4KB/s   00:00 

{: .output}

To download a file we type get some-file.txt:

sftp> get config.toml

{: .bash}

Fetching /global/home/yourUsername/config.toml to config.toml
/global/home/yourUsername/config.toml                               100%  713     9.3KB/s   00:00

{: .output}

And we can recursively put/get files by just adding -r. Note that the directory needs to be
present beforehand.

sftp> mkdir content
sftp> put -r content/

{: .bash}

Uploading content/ to /global/home/yourUsername/content
Entering content/
content/scheduler.md              100%   11KB  21.4KB/s   00:00
content/index.md                  100% 1051     7.2KB/s   00:00
content/transferring-files.md     100% 6117    36.6KB/s   00:00
content/.transferring-files.md.sw 100%   24KB  28.4KB/s   00:00
content/cluster.md                100% 5542    35.0KB/s   00:00
content/modules.md                100%   17KB 158.0KB/s   00:00
content/resources.md              100% 1115    29.9KB/s   00:00

{: .output}

To quit, we type exit or bye.

Transferring files interactively with FileZilla (sftp)

FileZilla is a cross-platform client for downloading and uploading files to and from a remote
computer. It is absolutely fool-proof and always works quite well. In fact, it uses the exact same
protocol as sftp under the hood. If sftp works, so will FileZilla!

Download and install the FileZilla client from
https://filezilla-project.org. After installing and opening the
program, you should end up with a window with a file browser of your local system on the left hand
side of the screen. When you connect to the cluster, your cluster files will appear on the right
hand side.

To connect to the cluster, we'll just need to enter our credentials at the top of the screen:

  • Host: sftp://login.cac.queensu.ca
  • User: Your cluster username
  • Password: Your cluster password
  • Port: (leave blank to use the default port)

Hit "Quickconnect" to connect! You should see your remote files appear on the right hand side of the
screen. You can drag-and-drop files between the left (local) and right (remote) sides of the screen
to transfer files.