Main Course Webpage

In-Class Lab 2: Practicing SCP and SFTP

Objective: Getting Familiar with SCP and SFTP

Parts One and Two practice transferring files between systems. You will start each logged onto a linux system. This means if you are using your laptop, you must ssh to hills, then to a linux system to start.

We will work through some of these together in-class but feel free to quietly move ahead. When you are ready, record your session using script and practice using good commenting etiquette.

Part One: SFTP

You should be logged into your linux (not hills!) account and connected to your home directory when you start this exercise. This exercise practices sftp.

  1. Create a directory in your home directory named stest. Connect to stest.

  2. Create a simple text file named sample that contains a few lines of text. The file should include your name or some other identifying text. (Note: you should not have a file named sample in your home directory on either linux or hills. If you do, you will overwrite it now or in a later step.)

  3. Change directory back to your home directory on linux.

  4. Open an sftp connection to hills.ccsf.edu.

  5. From within sftp, list the path of the current directory on hills and its contents. Then list the path of the current directory on linux and its contents.

  6. Still in sftp, change the current directory on linux to your stest directory. List the contents of the current directory on linux.

  7. Transfer the sample file from linux to hills. Still in sftp, list it on hills to be sure it is there. Then exit sftp. (Note that this transferred the file ~/stest/sample on linux to ~/sample on hills ) What directory are you in on linux after you exit sftp?

  8. Using ssh, connect to hills. Cat your sample file. Then delete your sample file from hills. Then exit back to linux.

Part Two: SCP

When you start this exercise, you should be logged onto linux and connected to your home directory. Your file ~/stest/sample should be intact on linux. Before you begin, write down the IP address of your linux machine. It should be taped to the top or front of the machine, and should be a number like 147.144.23.43 (I'll go over in class some other ways to get your IP address). If you are logged in remotely, use the command ip addr | grep inet and look for an address that starts with 147.144.23. (ignore the /24 after it))

  1. Staying in your home directory, transfer the file ~/stest/sample from linux to your home directory on hills using scp. (If scp did not ask you for your hills password, you probably forgot the colon (:) after the hills domain name.)

  2. ssh to hills and confirm that sample was transferred. Then delete it. Remain on hills.

  3. Transfer the stest directory and all of its contents from linux to your home (current) directory on hills using scp. Remember to use the IP address of your linux system to do the transfer. (It actually does not matter which linux system's IP address you use, so long as you are using your personal linux account.)

  4. Still on hills, check that the stest directory and its contents were transferred. Then delete stest and its contents.

  5. Still on hills, transfer the directory /pub/cs/grwoo/cs160a/wildcards recursively to your home directory on linux.

  6. Exit hills back to linux. Check that the wildcards directory was transferred. Then delete it and the stest directory recursively.

Submitting Your Homework Assignment

Transfer your output script session as an attachment on Canvas

If you find something particularly interesting, please include that in your homework submission as a comment. I may ask you to share your insights at the beginning of class for participation points.