Transferring files to and from the server
Following are some example commands for transferring files and folders to and from the server.
Remember:
-
You must have permissions to access the target folder on the server to which you wish to move your file
-
Your terminal must be on your computer to move files (that is, your pwd should be somewhere on your own computer)
-
The below formula will also work for moving files to/from NeSI
Transfer files from your own computer to the server
scp /path/to/file/FILENAME boros:/path/to/target/folder
(Note the colon ‘:’ after the server name.)
If your terminal is in the folder containing the file, you do not need the path:
scp FILENAME boros:/path/to/target/folder
Likewise, if you are transferring the file to your home folder on boros, then you do not need the path:
scp FILENAME boros:
Transferring to a subfolder in your home folder on boros:
scp FILENAME boros:scripts/
If the folder is in another part of boros, then you need to put the full path:
scp FILENAME boros:/scratch/hugh/subfolder/
If you want to upload an entire folder (make sure you want to move all the files), just add the -r argument:
scp -r /path/to/FOLDERNAME boros:/path/to/target/folder
Note that this will create a folder called FOLDERNAME within the target folder.
Transfer files from the server to your own computer
In order to move files from boros or another server to your own computer, the order of paths is reversed:
scp boros:/path/to/file/FILENAME /path/to/target/folder/
Note if your terminal is in the target folder (pwd), then you can just add a period at the end:
scp boros:/path/to/file/FILENAME .
The same rules apply for absolute paths. For example, if you are moving a file from your home folder on boros:
scp boros:FILENAME /path/to/target/folder/
You can also substitute the ~ (tilde) for the root path on your computer (e.g. ~/ instead of /Users/hughcross/)
And the same rules apply for downloading folders:
scp -r boros:/path/to/FOLDERNAME /path/to/target/folder
rsync: A better way?
You can also use the command line tool rsync to move files to and from the server. It has many uses, such as making regular backups to an external hard drive. rsync has some advantages over using scp, for example, you can update a folder you have already copied to the server, and it will only update the files that have changed (if it is a big folder, this can save lots of time).
For a single file
rsync FILENAME boros:/path/to/target/folder
It is better to use the -a
option, as that will preserve time stamp and permissions, etc. Here I have also added the -v
option (–verbose) which will output the status:
rsync -av FILENAME boros:/path/to/target/folder
For syncing folders it is the same command:
rsync -av /path/to/folder boros:/path/to/target/folder
And, the same thing transferring from the server to your computer:
rsync -av boros:/path/to/folder ~/Documents
If you add the --delete
option, any files on the target that are not on the source folder will be deleted. To avoid accidentally deleting any precious files, it is advised to use the --dry-run
command first, which will show you what would happen without actually doing anything:
rsync -av /path/to/source/folder --dry-run --delete scripts boros:/path/to/target/folder
Once you have checked it will do what you want, you can run without the dry-run
option
rsync -av /path/to/source/folder --delete scripts boros:/path/to/target/folder
As mentioned, you can do this to back up to an external hard drive:
rsync -av /path/to/source/folder /Volumes/NAME_OF_EXTERNAL_HD/target/folder