Bringing Files Over From a Machine at Another Institution

New faculty, staff, and students will often have files on machines at other institutions that they will want to bring over to Lick machines. Here's the easiest and safest way to do it:

Suppose that user lharden wants to copy her files from the host mars.astro.umd.edu. Her account is still active on mars, and her username there is lharden. The files she wants to transfer from her account on mars are file1, file2, thesis, and a directory (with subdirectories) named saturn. She wants her files to end up on bigdog. Here's what she should do:

  1. Log into bigdog as lharden.

    This procedure is greatly simplified if you log into the remote machine before transferring anything and put all the files you want to transfer into one directory (it's easiest if this directory is in your home directory). That directory may have as many subdirectories as you want, but should not contain any files that you do not want to transfer.

  2. ssh -l lharden mars.astro.umd.edu
  3. mkdir tolick
  4. cp file1 file2 thesis tolick
  5. cp -R saturn tolick/.
  6. log out of mars.astro.umd.edu.
  7. mkdir fromumd
  8. cd fromumd
  9. scp -r lharden@mars.astro.umd.edu: tolick . (Be sure to have a space after the directory containing files to be transferred, followed by a period.)

    This step copies the tolick directory from mars.astro.umd.edu to a subdirectory of the fromumd directory on bigdog. (In other words, the formerly empty fromumd directory now contains a subdirectory named tolick) Now we'll move the contents of tolick up to fromumd. (Some scp's don't accept shell metacharacters or wildcard characters, which is why we do it this way)

  10. cd tolick
  11. cp -R * ../. (Be sure to have a space between the asterisk and the two dots)
  12. rm -ir * The -i option will make rm ask before deleting any files. rm may be aliased to rm -i on your machine already, but better safe than sorry... If you have a lot of files, and don't want to be prompted before removing each one, make sure you are in the tolick directory, and type:
    rm -rf *
    WARNING: If you do this in the wrong directory, YOU COULD LOSE SOME OR ALL OF YOUR FILES.
    I recommend using rm -ir unless it would take literally hours to delete all of the files you transferred over.
  13. cd ..
  14. rmdir tolick

Now the files file1, file2, thesis, and the directory saturn (with all its subdirectories) from mars.astro.umd.edu are in the fromumd directory on bigdog. You can now copy them to wherever you want them to be.

If you transferred large files, or a large number of files, and disk space is a problem on the remote machine (mars), you may want to ssh back into that account and delete the tolick directory.


Why didn't you use tar or ftp to transfer the files over?

You could use tar or ftp to transfer the files. I prefer scp because it's easier and safer.

If you use this method exactly as directed, you are guaranteed not to lose any files (unless you use rm -rf in the wrong directory). If you are not accustomed to using tar, it's not that difficult to make a mistake that results in files being overwritten. Worse yet, these mistakes overwrite the original file, not just a copy of the file.

ftp has the disadvantage of not copying directories. This method allows you to copy your directories, keeping all the subdirectories in place.