Difference between revisions of "Tutorial6: File Transfer / Sending Email Messages"

From CDOT Wiki
Jump to: navigation, search
(INVESTIGATION 3: USING THE MAIL COMMAND TO SEND FILE ATTACHMENTS)
 
(625 intermediate revisions by 4 users not shown)
Line 1: Line 1:
=TRANSFERRING FILES / USING THE MAIL COMMAND=
+
{{Admon/caution|DO NOT USE THIS VERSION OF THE LAB. This page will no longer be updated.|'''New version here:''' https://seneca-ictoer.github.io/ULI101/A-Tutorials/tutorial6<br />'''Andrew's students please go here:''' http://wiki.littlesvr.ca/wiki/OPS145_Lab_6}}
 +
=TRANSFERRING FILES BETWEEN COMPUTERS=
 
<br>
 
<br>
 
===Main Objectives of this Practice Tutorial===
 
===Main Objectives of this Practice Tutorial===
  
:* List '''common utilities''' combined with the '''ssh''' suite of utilities
+
:* List '''common utilities''' contained in the '''ssh''' application framework
  
:* Securely copy files between Unix/Linux servers using the '''scp''' command
+
:* Securely '''copy''' files between Unix/Linux servers using the '''scp''' command
  
:* Securely transfer copies of files between Unix/Linux servers using the '''sftp''' command
+
:* Securely '''transfer''' copies of files between Unix/Linux servers using the '''sftp''' command
  
:* Use the mail command to send email messages to your Seneca email account
+
:* Use the '''ssh''' command to run  and view commands on a '''remote computer''' from a '''local computer'''.
  
:* Use the mail command to send email with file attachments to your Seneca email account
+
:* Use the '''mail''' command to send email with '''file attachments''' to your Seneca email account
 
<br>
 
<br>
  
Line 28: Line 29:
 
|- valign="top" style="padding-left:15px;"
 
|- valign="top" style="padding-left:15px;"
  
|colspan="2" |Course Notes:<ul><li>[https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week6.pdf PDF] | [https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week6.pptx PPTX]</li></ul>
+
|colspan="2" |'''Slides:'''<ul><li>Week 6 Lecture 1 Notes:<br> [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-6.1.pdf PDF] | [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-6.1.pptx PPTX]</li></ul>
  
|  style="padding-left:15px;" |Definitions:
+
|  style="padding-left:15px;" |'''Definitions:'''
 
* [https://en.wikipedia.org/wiki/Secure_copy Secure Copy]
 
* [https://en.wikipedia.org/wiki/Secure_copy Secure Copy]
 
* [https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol Secure File Transfer Protocol]
 
* [https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol Secure File Transfer Protocol]
 
* [https://en.wikipedia.org/wiki/Mail_(Unix) Email]<br><br>
 
* [https://en.wikipedia.org/wiki/Mail_(Unix) Email]<br><br>
  
|  style="padding-left:15px;"|File Transfer Commands:
+
|  style="padding-left:15px;"|'''File Transfer Commands:'''
 
* [http://man7.org/linux/man-pages/man1/scp.1.html scp]
 
* [http://man7.org/linux/man-pages/man1/scp.1.html scp]
 
* [http://man7.org/linux/man-pages/man1/sftp.1.html sftp]
 
* [http://man7.org/linux/man-pages/man1/sftp.1.html sftp]
 
* [https://man.openbsd.org/mail mail]
 
* [https://man.openbsd.org/mail mail]
  
|colspan="1" style="padding-left:15px;" width="30%"|Instructional Videos:<ul><li>[https://www.youtube.com/watch?v=EBvxbuhDKBw Using scp Command]</li><li>[https://www.youtube.com/watch?v=QcKYFEgfV-I Using sftp Command]</li><li>[https://www.youtube.com/watch?v=Iuf_mLrvh2o Using the mail Command]</li></ul>
+
|colspan="1" style="padding-left:15px;" width="30%"|'''Instructional Videos:'''<ul><li>[https://www.youtube.com/watch?v=EBvxbuhDKBw Using scp Command]</li><li>[https://www.youtube.com/watch?v=QcKYFEgfV-I Using sftp Command]</li><li>[https://www.youtube.com/watch?v=Iuf_mLrvh2o Using the mail Command]</li></ul>
 
|}
 
|}
  
 
= KEY CONCEPTS =
 
= KEY CONCEPTS =
  
The '''ssh''' Linux command is a '''suite of tools''' to allow the user to  issue commands<br>securely between Unix / Linux servers, as well as copy and transfer files among Unix/Linux servers.
+
The '''ssh''' Linux command is a '''suite of tools''' to allow the user to  issue Linux commands securely between <br>Unix / Linux servers, as well as securely '''copy''' and '''transfer''' files among Unix/Linux servers.
  
 
In this tutorial, you will learn several different methods to securely transfer files from your Matrix Linux account<br>to other computers using Linux commands including '''scp''', '''sftp''' and '''mail'''.
 
In this tutorial, you will learn several different methods to securely transfer files from your Matrix Linux account<br>to other computers using Linux commands including '''scp''', '''sftp''' and '''mail'''.
  
===Secure Copy (scp)===
 
  
[[Image:scp-diagram.png|thumb|right|450px|The '''scp''' Unix/Linux command is used to securely copy files between Unix/Linux servers.]]
+
===Issuing Commands on Remote Unix/Linux Servers===
''Secure copy protocol ('''scp''') is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. "SCP" commonly refers to both the Secure Copy Protocol and the program itself.''
+
[[Image:ssh-remote.png|thumb|right|350px|The '''ssh''' command can be used to <u>run</u> and <u>view</u> commands on '''remote computer''' from a '''local computer'''.
 +
]]
 +
You can use the '''ssh''' command to issue Unix/Linux commands on a '''remote''' server<br>from your <u>local</u> computer without logging into a remote server (such as Matrix).
 +
 
 +
 
 +
''Command Usage:''
  
Reference: https://en.wikipedia.org/wiki/Secure_copy
+
<span style="font-family:courier">'''ssh username@matrix.senecacollege.ca ls -l'''</span>
  
 +
You will be prompted for your Matrix account password, then the contents of your home directory in your remote Matrix account will be displayed on your <u>local</u> computer's terminal.
 +
<br><br>
  
The usage for the '''scp''' command is similar to the '''cp''' command with the addition of host  names, for example:
+
===Secure Copy (scp)===
  
'''scp local.file user@host:destination-pathname'''  
+
[[Image:scp-diagram.png|thumb|right|350px|The '''scp''' Unix/Linux command is used to securely copy files between Unix/Linux servers.]]
 +
The '''scp''' command is used to <u>securely</u> copy files between your '''local''' computer and '''remote''' Unix/Linux server. The usage for the ''scp'' command is similar to the '''cp''' command with the addition of '''user name''' and '''host name'''.
  
'''scp local.file user@host:'''
 
  
'''scp local.file host:'''
+
''Command Usage:''
  
 +
<span style="font-family:courier">'''scp local.file username@host:destination-pathname'''<br>'''scp local.file username@host:'''<br>'''scp user@host:file-pathname local-pathname'''<br><br></span>
  
 
The most common '''mistake''' that students make is forgetting to add<br>the '''colon''' character ":" <u>after</u> the remote hostname.
 
The most common '''mistake''' that students make is forgetting to add<br>the '''colon''' character ":" <u>after</u> the remote hostname.
  
The user name in the command can be '''omitted''' if it's the  same as on the local host.
+
The user name in the command can be '''omitted''' if it's the  same as on the <u>local</u> host.<br>Multiple file and recursive directory copy (i.e. option '''-r''') is supported.
 
 
Multiple file and recursive directory copy (i.e. option '''-R''') is supported.
 
 
<br><br>
 
<br><br>
  
Line 76: Line 82:
  
 
[[Image:sftp-diagram.png|thumb|right|350px|The '''sftp''' Unix/Linux command is used to securely transfer (copy) files between Unix/Linux servers.]]
 
[[Image:sftp-diagram.png|thumb|right|350px|The '''sftp''' Unix/Linux command is used to securely transfer (copy) files between Unix/Linux servers.]]
''<span style="font-weight:bold">sftp</span> is a file transfer program, similar to ftp, which performs all operations over an encrypted ssh transport.  It may also use many features of ssh, such as '''public key authentication''' and '''compression'''.''
 
  
Reference: http://man7.org/linux/man-pages/man1/sftp.1.html
+
'''FTP''' stands for '''File Transfer Protocol''' which provides a set of '''rules''' on how to convert data that is transferred between computers (both identical and different operating systems). The '''sftp''' command performs file transfers <u>securely</u> using encryption.
  
'''FTP''' is an acronym for '''File Transfer Protocol''' which provides a set of '''rules''' on how to convert data that is transferred between computer servers (both identical and different).
 
  
 +
''Command Usage:''
  
When you login via the sftp command, you are in the '''sftp prompt''' (like a Bash shell prompt, but with a<br>limited number of commands).
+
'''<span style="font-family:courier">sftp username@hostname</span>'''  
When issuing sftp commands it is important to understand that the local server relates to the server where you first issues the sftp command.
 
  
Below is a table that provides sftp commands to perform basic transfer and file management commands. Some of those commands loosely resemble Unix/Linux commands.
 
  
 +
When you login via the ''sftp'' command, the '''sftp prompt''' appears. The sftp prompt is like a Bash shell prompt, but with a limited number of commands. When issuing sftp commands, the local server relates to the server where you first issued the sftp command. Refer to the diagram on the right for <u>local</u> and <u>remote</u> ''sftp'' commands.
 +
[[Image:graphical-sftp-application.png|thumb|right|250px|'''Graphical''' SFTP application.]]
  
<table border="1" cellspacing="0" cellpadding="5"><tr style="text-align:center;"><th>Operation</th><td>'''sftp Command'''<br>(Local Server)</td><td>'''sftp Command'''<br>(Remote Server)</td></tr><tr><td>Display current working directory</td><th>!pwd</th><th>pwd</th></tr><tr><td>Display directory contents</td><th>!ls</th><th>ls</th></tr><tr><td>Create Directory</td><th>!mkdir</th><th>mkdir</th></tr><tr><td>Change directory location</td><th>lcd</th><th>cd</th></tr><tr><td>Upload file to remote server</td><th>put</th><th>-</th></tr><tr><td>Download file to local server</td><th>get</th><th>-</th></tr></table>
+
 
<br><br>
+
'''<big>Graphical SFTP Applications</big>'''
 +
 
 +
Although it is important to know how to use the '''sftp''' command for ''quizzes'', ''midterm'' and ''final exam'',<br>there are '''graphical sftp applications''' that provide an alternative to issuing commands.
 +
 
 +
If you installed the graphical '''Secure Shell Client''' application in your Windows computer from performing [https://wiki.cdot.senecacollege.ca/wiki/Tutorial_1:_Using_Your_Matrix_Server_Account#CONNECTING_TO_YOUR_MATRIX_ACCOUNT_FROM_A_GRAPHICAL_WINDOWS_APPLICATION TUTORIAL 1 INVESTIGATION 1], you can use this application to transfer files between your computer and your Matrix account by graphically '''navigating''', '''selecting''' and '''dragging''' files between computers.
 +
<br>
  
 
===Sending Emails with File Attachment (mail)===
 
===Sending Emails with File Attachment (mail)===
 
   
 
   
[[Image:mail-diagram.png|thumb|right|350px|The '''mail''' command allows users to send and receive email messages. (Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]
 
''<span style="font-weight:bold;">mail</span> is a command-line email client for Unix and Unix-like operating systems.''
 
  
Reference: https://en.wikipedia.org/wiki/Mail_(Unix)
+
You can use the '''mail''' command in Matrix to send email messages<br>to other email accounts via the Internet.
 +
 
  
 +
[[Image:mail-diagram.png|thumb|right|400px|Using the '''mail''' command with '''redirection''' to send email<br>with file attachment.]]
 +
'''Sending a Simple Email Message:'''
  
'''Steps when sending email (Method 1):'''
+
:#Type: '''<span style="font-family:courier;">mail username@hostname''' and press '''ENTER''' </span><br>
 +
:#Enter '''subject line''' and press '''ENTER'''<br>
 +
:#Type the '''body of the message''' and then when finished,<br>press <span style="font-family:courier">'''ctrl+d'''</span> to send message<br><br>
  
:#Type: '''mail recipient@hostname''' and press '''ENTER''' <br>
+
'''Sending an Email Message with a File Attachment:'''
 +
[[Image:mail-diagram-2.png|thumb|right|275px|Viewing email with file attachment in<br>'''Seneca email account'''.]]
 +
:#Type: '''<span style="font-family:courier;">mail username@hostname -a filepathname</span>''' and press '''ENTER''' <br>
 
:#Enter '''subject line''' and press '''ENTER'''<br>
 
:#Enter '''subject line''' and press '''ENTER'''<br>
:#Type the '''body of the message''' and then when finished, press '''ctrl+d''' to send message<br><br>'''NOTE:''' You can use the mail command with the '''-a''' option to specify a file to send<br>as an attachment to your email message.<br><br>''Example:''<br>'''mail recipient@hostname -a filename'''
+
:#Type the '''body of the message''' and then when finished, press <span style="font-family:courier">'''ctrl+d'''</span> to send message<br><br>
 +
 
 +
'''Alternative Method of Sending an Email Message with a File Attachment:'''
  
 +
:#Type: '''<span style="font-family:courier;">mail -s "subject line" username@hostname < filepathname</span>'''
 +
:#Press '''ENTER''' to send<br><br>'''NOTE:''' You would have to use this method since you have used '''stdin''' redirection<br>to attach the file’s so you can’t input the subject line from the terminal!<br><br>
  
'''Steps when sending email (Method 2):'''
+
=INVESTIGATION 1: FILE TRANSFER (SECURE COPY)=
  
::: Use the '''-s''' option in the command to specify the subject line of the command and use stdin redirection to send a text file as the body of the message.<br><br>'''NOTE:''' The advantage of using this method is that you can send an email message without being prompted for the subject line or body of text message.<br><br>''Example:''<br>'''mail -s "your subject line" recipient@hostname < filename'''
+
<span style="color:red;">'''ATTENTION''': This online tutorial will be required to be completed by '''Friday in week 8 by midnight''' to obtain a grade of '''2%''' towards this course</span><br><br>
<br><br>
 
  
=INVESTIGATION 1: USING SECURE COPY=
+
[[Image:cmd.png|thumb|right|350px|Make certain to '''open a command-line terminal''' and<br><u>'''NOT'''</u> a graphic SSH application for this tutorial!.]]
 +
The '''SSH''' package on your ''home computer'' and on the ''Matrix Linux server''<br>contain a '''suite''' (i.e. collection) of secure utilities including '''ssh''' and '''scp'''.
  
<br>
 
In this section, you will learn how to use the '''scp''' command.
 
  
<span style="color:blue;">'''ATTENTION:''' Since the only server account you have is your '''Matrix''' server,<br>we will simulate using the scp command to copy from your '''Matrix''' server to<br>'''<u>another instance</u> of your Matrix server'''.<br><br>To make this work, we will need to edit a "start-up" file to place a special series of commands.<br>You will learn more about start-up files later in this course.</span>
+
In this investigation, you will learn how to use the '''scp''' command to '''securely copy files''' between your computer and your Matrix Linux server. This methods is useful because it can be performed in the ''MS-Windows'', ''MacOSx'', and ''Unix/Linux'' operating systems.<br><br>You will also learn how to issue the '''ssh''' command to run commands on your<br><u>'''remote'''</u> Matrix server while remaining on your <u>'''local'''</u> computer.
  
  
 
'''Perform the Following Steps:'''
 
'''Perform the Following Steps:'''
  
# '''Login''' your matrix account and issue a command to '''confirm''' you are located in your '''home''' directory.<br><br>
+
# Determine which operating system that your computer is using.<br><br>
# Issue the following Linux commands to create the following directories:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/from<br>mkdir ~/destination</span><br><br>
+
# Connect to your Matrix account using the instructions in the table below based on <u>your</u> '''current operating system'''.<br><br>
# Change to the '''~/from''' directory.<br><br>
+
<table style="margin-left:50px;">
# Use a text editor to create a text file called '''myfile.txt'''<br><br>
+
  <tr valign="top" style="text-align:center;">
# Enter the following two lines displayed below in your editing session:<br><span style="font-family:courier;font-weight:bold;">This is my file<br>It is a small file</span><br><br>
+
    <th>'''Newer Version of Windows 10:'''</th>
# '''Save''' editing changes to your ''myfile.txt'' file and exit your text editor.<br><br>
+
    <th>'''MacOSX:''' </th>
# Change back to your '''home''' directory and confirm that you are located in your ''home'' directory.<br><br>Let's run a '''shell script''' to check that you created the correct directories<br>and that you created the '''myfile.txt''' file (with correct file contents) in the '''~/from''' directory<br>before using the ''scp'' Linux command.<br><br>
+
    <th>'''Linux:''' </th>
# Issue the following Linux command to run that checking script: <span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week6-check-1</span><br><br>
+
  </tr>
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message, and proceed to the next step.<br><br>'''NOTE:''' As previously mentioned, we will simulate using the scp on another instance of our Matrix server. <br>To make this work, we will need to edit a "start-up" file to place a special series of commands<br><br>
+
  <tr>
# Use a text editor to edit the following start-up file: '''~/.bashrc'''<br><br>
+
<td>
# Enter the following text (shown below) at the '''TOP''' of this startup file:<br><span style="color:#8B0000;font-family:courier;">[[ $- == *i* ]] || return  </span><br><br>
+
*From the start menu, type '''cmd''' and launch program
# '''Save''' editing changes to this startup file and exit your text editor.<br><br>
+
*In the command terminal, enter the following command:<br><span style="color:blue;font-weight:bold;font-size:.75em;">ssh senecausername@matrix.senecacollege.ca</span>
# Issue the following Linux command to confirm that the '''~/destination''' directory is empty:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls ~/destination</span><br><br>
+
    </td>
# Issue the following Linux command to copy the myfile.txt from your local server to your remote server (i.e. yoursenecaid is YOUR Seneca ID):<br><span style="color:blue;font-weight:bold;font-family:courier;">scp myfile.txt yoursenecaid@matrix.senecacollege.ca:/destination</span><br><br>'''NOTE:''' You may be required to enter '''yes''' to have the public key shared.<br><br>
+
    <td>
# When prompted, enter your Matrix '''password'''.<br><br>
+
*Click ''Launchpad'' icon, type '''terminal'''<br>and press '''ENTER'''
# Issue the same Linux command that you issued in '''step #13'''.<br><br>What did you notice?<br><br>
+
*In the terminal, enter the following command:<br><span style="color:blue;font-weight:bold;font-size:.75em;">ssh senecausername@matrix.senecacollege.ca</span>
# Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">scp myfile.txt yoursenecaid@matrix.senecacollege.ca:</span><br><br>Where do you think this file was copied to on your remote server?<br><br>
+
    </td>
# Issue the '''ls''' command for the home directory.<br><br>What do you see?<br>What does this tell you about how the previously-issued command works with just a colon?<br><br>
+
    <td>
# Issue the following Linux command (leaving-out the colon character at the end): <br><span style="color:blue;font-weight:bold;font-family:courier;">scp myfile.txt yoursenecaid@matrix.senecacollege.ca</span><br><br>What happened?<br><br>
+
*From the menu, choose:<br>'''Applications''' > '''System Tools''' > '''Terminal'''
# Make certain that your current directory is your '''home''' directory.<br><br>
+
*In the terminal, enter the following command:<br><span style="color:blue;font-weight:bold;font-size:.75em;">ssh senecausername@matrix.senecacollege.ca</span>
# Issue the following Linux command to run a checking script to ensure you created the CORRECT directories, created and copied the correct files: <br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week6-check-2</span><br><br>
+
    </td>
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.<br><br>
+
  </tr>
:In the next investigation, you will use the '''sftp''' Linux command to transfer (i.e. copy) files between servers.<br><br>
+
</table><br>
 +
<ol><li value="3">'''NOTE:''' Make certain to open a '''command-line terminal''' and <u>NOT</u> a <u>graphical</u> SSH application for this tutorial.<br><br></li><li>After logging into your Matrix account, issue to the '''pwd''' command to confirm you are in your home directory.<br><br></li><li>Issue the following Linux command to create the following directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/remote</span><br><br></li><li>Change to the <b>~/remote</b> directory and confirm that you have changed to that directory.<br><br></li><li>Use a text editor to create a text file called <b>myfile.txt</b><br><br></li><li>Enter the following two lines displayed below in your editing session:<br><span style="font-family:courier;font-weight:bold;">This is my file<br>It is a small file</span><br><br></li><li><b>Save</b> editing changes to your ''myfile.txt'' file and exit your text editor.<br><br></li><li>Let's run a <b>shell script</b> to check that you created the <b>remote</b> directory<br>and that you created the <b>myfile.txt</b> file (with correct file contents) in that directory.<br><br></li></li>Enter the following command: <span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week6-check-1</span><br><br></li><li>If you encounter errors, make corrections and then re-run the checking script until you receive<br>a congratulations message, and proceed to the next step.<br><br><b>NOTE:</b> We will now learn to transfer files between your <b><u>local</u> home computer</b> and your <b><u>remote</u> Matrix Linux server</b>.<br><br></li></ol>[[Image:cmd.png|thumb|right|350px|You are required to <u>'''remain'''</u> in your '''local''' computer's command terminal for the remainder of this ''INVESTIGATION'' and ''INVESTIGATION 2'']]
 +
<ol><li value="12">'''Exit your Matrix ssh session''' but '''<u>remain</u>''' in the ''command terminal''<br>on your '''local''' computer..<br><br><span style="color:blue;">'''ATTENTION:''' You are required to <u>'''remain'''</u> in your '''local''' computer's command terminal for the remainder of this ''INVESTIGATION'' and ''INVESTIGATION 2''.</span><br><br></li><li>The <b>mkdir</b> command works with <i>MS Windows/UNIX/Linux/MacOSx computers</i>.<br>Issue the following command on your <u>local</u> computer to<br>create a directory called <b>local</b>: <span style="color:blue;font-family:courier;font-weight:bold;">mkdir local</span><br><br></li><li>The <b>cd</b> command works with <i>MS Windows/UNIX/Linux/MacOSx computers</i>.<br>Issue the following command on your <u>local</u> computer to<br>change to the <b>local</b> directory: <span style="color:blue;font-family:courier;font-weight:bold;">cd local</span><br><br></li><li>If you are using MS Windows on your local computer, issue the <span style="color:blue;font-weight:bold;font-family:courier;">dir</span> command to confirm you are<br>in the ''local'' directory; otherwise, use the <span style="color:blue;font-weight:bold;font-family:courier;">pwd</span> command.<br><br></li> <li>If you are in MS Windows, open the '''GRAPHICAL''' <span style="color:blue;font-family:courier;font-weight:bold;">NotePad</span> application to create a text file<br>(Otherwise, use the <b>nano</b> or <b>vi</b> text editor).<br><br></li><li>Enter a few lines of text, and if using '''Notepad''', then click on the <b>File</b> menu and select <b>save as</b><br>(save as the filename <span style="color:blue;font-weight:bold;font-family:courier;">other.txt</span> in your <span style="color:blue;font-weight:bold;font-family:courier;">local</span> directory) and then <b>exit</b> the <i>Notepad</i> text editor.<br><br>'''NOTE:''' if using another text editor, save your editing session and exit the text editor.<br><br></li><li>If your OS is MS Windows issue the <span style="color:blue;font-family:courier;font-weight:bold;">dir</span> Windows command to view the contents of your current directory<br>(otherwise, issue the <span style="color:blue;font-family:courier;font-weight:bold;">ls</span> command for other operating systems).<br><br>We will use the '''scp''' command to copy the <u>local</u> file called '''other.txt''' to your home directory on your <u>remote</u> Matrix Linux server.<br><br></li><li>Issue the following Linux command to copy the <b>other.txt</b> file from your local machine to your remote Matrix server<br>(replace yoursenecaid is <u>YOUR</u> Seneca ID and '''ADD A COLON : TO THE END OF THE COMMAND'''):<br><span style="color:blue;font-weight:bold;font-family:courier;">scp other.txt yoursenecaid@matrix.senecacollege.ca:</span><br><br></li><li>When prompted, enter your Matrix '''password'''.<br>[[Image:scp-diagram-2.png|thumb|right|350px|You can issue the ssh command, followed by a '''command''' that will be run on your '''remote''' computer,<br>but <u>display</u> command output on your '''local''' computer.]]<br><b>TIP:</b> You can issue the ssh command, followed by a command that will be run on your remote computer, but display on your local computer <b><u>without</u></b> having to establish a continuous connection to your remote Matrix server.<br><br></li><li>Issue the following command (using your matrix username):<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l other.txt</span><br><br></li><li>When prompted, '''enter your password''' and press '''ENTER'''.<br><br>Do you see detailed information <b>other.txt</b> file? (look at bottom)<br>That command was run remotely on your Matrix server as confirmation that you securely copied that file to the home directory of the Matrix server.<br><br>Let's copy the file called '''myfile.txt''' in the '''~/remote''' directory that you created earlier in your Matrix account to your <b>local</b> directory on your home computer.<br><br></li><li>Issue the following Linux command (replace yoursenecaid is <u>YOUR</u> Seneca ID).<br> The period "." as '''second argument''' represents your <u>current</u> directory<br>on your <u>local</u> computer):<br><span style="color:blue;font-weight:bold;font-family:courier;">scp  yoursenecaid@matrix.senecacollege.ca:remote/myfile.txt .</span><br><br></li><li>Issue the <span style="color:blue;font-weight:bold;font-family:courier;">dir</span> or <span style="color:blue;font-weight:bold;font-family:courier;">ls</span> command (depending on the OS of your <u>local</u> computer) to confirmed your properly copied that file from Matrix.<br><br></li><li>Use the '''Notepad''' application (or vi for other OS types) to create a text file called <span style="color:blue;font-weight:bold;font-family:courier;">mytextfile.txt</span>,<br>type some text and then save in the <span style="color:blue;font-weight:bold;font-family:courier;">local</span> directory of your computer.<br><br><li>Issue the <b>dir</b> or <b>ls</b> command (depending on your OS) to confirm that your newly-created file exists in your <b>local</b> directory.<br><br></li><li>We are going to intentionally make a '''<u>mistake</u>''' with the '''scp''' command.<br>Issue the following Linux command to copy the <b>mytextfile.txt</b> file from your local machine to your remote Matrix server<br>(replace yoursenecaid is <u>YOUR</u> Seneca ID and DO <u>NOT</u> INCLUDE THE : at the end of the command so see what happens):<br><span style="color:blue;font-weight:bold;font-family:courier;">scp mytextfile.txt yoursenecaid@matrix.senecacollege.ca</span><br><br>Did you notice anything different (i.e. no password)?<br><br></li><li>Issue the following command (using your matrix username):<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l mytextfile.txt</span><br><br></li><li>When prompted, enter your password and press ENTER.<br><br><b>The file mytextfile.txt does NOT appear in your home directory on your Matrix server!<br>Note that the COLON was NOT added to the end of the command! Therefore, you MUST<br>remember to include the COLON : at the end of the hostname, or it will NOT remotely copy the file!</b><br><br></li><li>Issue the following command to properly copy that same file to your Matrix server:<br><span style="color:blue;font-weight:bold;font-family:courier;">scp mytextfile.txt yoursenecaid@matrix.senecacollege.ca:</span><br><br></li><li>Issue the following command to confirm that it was remotely copied to your <b>home</b> directory in Matrix:<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l /home/yoursenecaid/mytextfile.txt</span><br><br>Do you see the output for the detailed file listing of <b>mytextfile.txt</b>?<br>What does  this indicate?<br><br><li>Issue the following command to copy the '''other.txt''' file on your local computer to the '''~/remote''' directory in Matrix renaming it as '''different.txt''':<br><span style="color:blue;font-weight:bold;font-family:courier;">scp other.txt yoursenecaid@matrix.senecacollege.ca:remote/different.txt</span><br><br></li><li>Issue the following command to confirm that the file was remotely copied to your '''~/remote''' directory in Matrix with a different filename:<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l /home/yoursenecaid/remote/different.txt</span><br><br>Were you able to properly copy this file?<br><br>Let's issue a checking script remotely to see that you properly copied that file from your<br>local computer to your remote Linux server to both your <b>home</b> directory and <b>~/remote</b> directory.<br><br></li><li>Issue the following:<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ~uli101/week6-check-2</span><br><br>If you encounter errors, re-run the scp commands to correct and re-run the above command until you receive a congratulations message.<br><br></li><li>Remain in the terminal on your <u>local</u> computer and proceed to ''INVESTIGATION 2''.<br><br></ol>
 +
 
 +
:In the next investigation, you will use the '''sftp''' Linux command to transfer (i.e. copy) files between your local computer and the Matrix server.<br><br>
 +
 
 +
<!-- RESIDUAL FROM LESS EFFECTIVE METHOD OF COPYING FILES BETWEEN SERVERS
 +
 
 +
<span style="color:blue;">'''ATTENTION:''' Since the only server account you have is your '''Matrix''' server,<br>we will simulate using the scp command to copy from your '''Matrix''' server to<br>'''<u>another instance</u> of your Matrix server'''.<br><br>To make this work, we will need to edit a "start-up" file to place a special series of commands.<br>You will learn more about start-up files later in this course.</span><br><br>
 +
# Use a text editor to edit the following start-up file: '''<span style="font-family:courier">~/.bashrc</span>'''<br><br>
 +
# '''Copy''' and '''paste''' the following text (shown below) at the '''TOP''' of your startup file:<br><span style="font-family:courier;font-weight:bold;">&#91;&#91; $- == *i* &#93;&#93; || return  </span><br><br>
 +
# '''Save''' editing changes to this startup file and exit your text editor.<br><br> -->
 +
 
 +
=INVESTIGATION 2: FILE TRANSFER (SECURE FTP) =
 +
 
 +
The '''SSH''' package on your ''home computer'' and on the ''Matrix Linux server''<br>contain a '''suite''' (i.e. collection)of secure utilities including '''ssh''' and '''sftp'''.
 +
 
  
=INVESTIGATION 2: USING SECURE FILE TRANSMISSION CONTROL PROTOCOL =
+
In this investigation, you will learn how to use the '''sftp''' command to '''transfer''' files between<br>Unix/Linux servers. This methods is useful because it can be performed in the<br>''MS-Windows'', ''MacOSx'', and ''Unix/Linux'' operating systems.<br><br>You will also learn how to issue the '''ssh''' command to run commands on your<br><u>'''remote'''</u> Matrix server while remaining on your <u>'''local'''</u> computer.
  
In this section, you will learn how to use the '''sftp''' command to transfer files between Unix/Linux servers and perform some basic directory navigation/management operations.
 
  
 +
=== Command Line Terminal (CLI) ===
  
<span style="color:blue;">'''NOTE:''' Since the only server account you have is your '''Matrix''' server, we will simulate using the sftp command to transfer/copy from your '''Matrix''' server to '''<u>another instance</u> of your Matrix server'''. You are NOT required to edit your ''.bashrc'' file to make this work since you already performed that operation in the previous investigation.</span>
+
Let's look at using the '''sftp''' command on your '''local''' machine.
  
  
 
'''Perform the Following Steps:'''
 
'''Perform the Following Steps:'''
 +
[[Image:cmd.png|thumb|right|275px|Make certain to <u>remain</u> in the<br>command-line terminal in your '''local''' computer.]]
 +
# Make certain that you are in a command terminal on your <u>local</u> computer<br>(i.e. do '''NOT''' log into your Matrix account).<br><br>
 +
# Issue a command (depending on your OS) to confirm that you are located in the '''local''' directory in your home computer.<br><br>
 +
# If you are in MS Windows, open the <span style="color:blue;font-family:courier;font-weight:bold;">NotePad</span> application to create a text file<br>(otherwise: use another text editor like <b>vi</b> or <b>nano)</b><br>.
 +
# Enter a few lines of text, and then click on the <b>File</b> menu and select <b>save as</b><br>(save as the filename <span style="color:blue;font-weight:bold;font-family:courier;">thefile.txt</span> in your <span style="color:blue;font-weight:bold;font-family:courier;">local</span> directory) and then <b>exit</b> the <i>Notepad</i> text editor.<br><br>If you using another OS, then save-as using the same filename and directory location for the text editor you are using.<br><br>
 +
# If your OS is MS Windows issue the <span style="color:blue;font-family:courier;font-weight:bold;">dir</span> Windows command to view the contents of your current directory<br>(otherwise, issue the <b>ls</b> command for other operating systems).<br><br>'''Note:''' the <u>relative</u> pathname symbols "'''.'''" and "'''..'''" work for the ''Windows''/''MacOSx''/''Unix''/''Linux'' operating systems.<br><br>
 +
# Issue the following command to move to the '''parent''' directory: <span style="color:blue;font-family:courier;font-weight:bold;">cd ..</span><br><br>
 +
# If your OS is MS Windows issue the <span style="color:blue;font-family:courier;font-weight:bold;">dir</span> Windows command to view the contents of that parent directory that you changed to<br>(otherwise, issue the <b>ls</b> command for other operating systems).<br><br>
 +
# Issue the following command to start an '''sftp''' session (note: yoursenecaid is YOUR Seneca ID):<br><span style="color:blue;font-weight:bold;font-family:courier;">sftp yoursenecaid@matrix.senecacollege.ca</span><br><br>'''NOTE:''' You may be required to enter '''yes''' to have the public key shared.<br><br>[[Image:sftp-commands.png|thumb|right|350px|Common '''sftp''' commands to  manage the transfer<br>of files between computers.]]
 +
# You should be in the '''sftp command prompt''' where you are expected to issue '''sftp commands'''. Please take a moment to view common<br><u>local</u> and <u>remote</u> ''sftp commands'' on the right-side table.<br><br>
 +
# Issue the following ''sftp command'': <span style="color:blue;font-weight:bold;font-family:courier;">pwd</span><br><br>What is the pathname? Which server does this represent: local or remote?<br><br>
 +
# Issue the following ''sftp command'': <span style="color:blue;font-weight:bold;font-family:courier;">lpwd</span><br><br>What is the pathname? Which server does this represent: local or remote?<br><br>
 +
# Issue the following ''sftp command'' to create a directory on your remote server: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir remote2</span><br><br>
 +
# Issue the following ''sftp command'' to confirm that the '''remote2''' directory has been created<br>in your remote server's home directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls</span><br><br>
 +
# Issue the following ''sftp command'' to change to the '''remote2''' directory on your ''remote'' server:<br><span style="color:blue;font-weight:bold;font-family:courier;">cd remote2</span><br><br>
 +
# Issue the '''pwd''' ''sftp command'' to confirm that you have changed to the ''remote2'' directory on your remote server.<br><br>
 +
# Issue the following sftp command to change to the '''local''' directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd local</span><br><br>
 +
# Issue the '''lpwd''' ''sftp command'' to confirm that you have changed to the ''local'' directory on your local computer.<br><br>
 +
# Issue the following ''sftp command'' to transfer the file called '''thefile.txt''' to the '''~/remote2''' directory on your remote server:<br><span style="color:blue;font-weight:bold;font-family:courier;">put thefile.txt</span><br><br>
 +
# Issue the '''ls''' sftp command to confirmed that you transferred the file called: '''thefile.txt'''<br><br>Let's create another directory on your local computer called '''local2''' so we can learn to <u>download</u> a file from your remote directory.<br><br>
 +
# Issue the following ''sftp command'' to change to the '''parent''' directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd ..</span><br><br>
 +
# Issue the '''lpwd''' ''sftp command'' to confirm that your current working directory on your local computer is your home directory.<br><Br>
 +
# Issue the following ''sftp command'' to create the following directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lmkdir local2</span><br><br>
 +
# Issue the following ''sftp command'' to change to the '''local2''' directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd local2</span><br><br>
 +
# Issue the '''lpwd''' ''sftp command'' to confirm you have changed to the '''local2''' directory on your local computer.<br><br>Let's learn to <u>download</u> a file from your remote server to your local computer.<br><br>
 +
# Issue the following '''sftp command''' to transfer your '''thefile.txt''' file from the '''remote2''' directory<br>on your remote server to your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">get thefile.txt</span><br><br>
 +
# Issue the <span style="font-weight:bold;font-family:courier;">lls</span> ''sftp command'' to confirm that you transferred the file '''thefile.txt''' to your local computer.<br><br>
 +
# Issue the following ''sftp command'' to exit the sftp utlilty: <span style="color:blue;font-weight:bold;font-family:courier;">exit</span><br><br>
 +
# Issue the following Linux command to remotely run a checking script to ensure you created the correct directories<br>and properly transferred those created files: <br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ~uli101/week6-check-3</span><br><br>
 +
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.<br><br>'''FYI:''' To run a checking program to check if you created the '''local''' and '''local2''' directories in MS Windows would require<br>running a local-based script (like '''PowerShell'''). Since this is a Unix/Linux based course, we don't have a PowerShell script,<br>so we will ignore checking for files transferred to your local computer.
 +
 +
<!-- OLDER CONTENT
  
 
# Make certain that you are logged into your Matrix account and are located in your '''home''' directory.<br><br>
 
# Make certain that you are logged into your Matrix account and are located in your '''home''' directory.<br><br>
# Issue the following Linux commands to create the following directories:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/local<br>mkdir ~/remote</span><br><br>
+
# Issue the following Linux commands to create the following directories:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/local</span><br><br>
 
# Change to the '''~/local''' directory.<br><br>
 
# Change to the '''~/local''' directory.<br><br>
 
# Use a text editor to create a text file called '''thefile.txt'''<br><br>
 
# Use a text editor to create a text file called '''thefile.txt'''<br><br>
 
# Enter the following two lines displayed below for this text file:<br><span style="font-family:courier;font-weight:bold;">This is my file called thefile.txt<br>It is also a small file</span><br><br>
 
# Enter the following two lines displayed below for this text file:<br><span style="font-family:courier;font-weight:bold;">This is my file called thefile.txt<br>It is also a small file</span><br><br>
# '''Save''' editing changes to the text files and exit your text editor.<br><br>
+
# '''Save''' editing changes to the text file and exit your text editor.<br><br>
 
# Change back to your '''home''' directory and confirm that you are located in your ''home'' directory.<br><br>Let's run a '''shell script''' to check to make certain that you created the correct directories<br>and that you created the '''myfile.txt''' file (with correct file contents) in the '''~/local''' directory<br>before learning to use the ''sftp'' Linux command.<br><br>
 
# Change back to your '''home''' directory and confirm that you are located in your ''home'' directory.<br><br>Let's run a '''shell script''' to check to make certain that you created the correct directories<br>and that you created the '''myfile.txt''' file (with correct file contents) in the '''~/local''' directory<br>before learning to use the ''sftp'' Linux command.<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week6-check-3</span><br><br>
+
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week6-check-3</span><br><br>
 
# Issue the following Linux command to start an sftp session (note: yoursenecaid is YOUR Seneca ID):<br><span style="color:blue;font-weight:bold;font-family:courier;">sftp yoursenecaid@matrix.senecacollege.ca</span><br><br>'''NOTE:''' You may be required to enter '''yes''' to have the public key shared.<br><br>You are now in the '''sftp command prompt''' where you are expected to issue '''sftp commands'''.<br>Please refer to the table of ''sftp commands'' in the '''KEY CONCEPTS''' section for reference.<br><br>
 
# Issue the following Linux command to start an sftp session (note: yoursenecaid is YOUR Seneca ID):<br><span style="color:blue;font-weight:bold;font-family:courier;">sftp yoursenecaid@matrix.senecacollege.ca</span><br><br>'''NOTE:''' You may be required to enter '''yes''' to have the public key shared.<br><br>You are now in the '''sftp command prompt''' where you are expected to issue '''sftp commands'''.<br>Please refer to the table of ''sftp commands'' in the '''KEY CONCEPTS''' section for reference.<br><br>
 
# Issue the following ''sftp command'': <span style="color:blue;font-weight:bold;font-family:courier;">pwd</span><br><br>What is the pathname? Which server does this represent: local or remote?<br><br>
 
# Issue the following ''sftp command'': <span style="color:blue;font-weight:bold;font-family:courier;">pwd</span><br><br>What is the pathname? Which server does this represent: local or remote?<br><br>
# Issue the following ''sftp command'': <span style="color:blue;font-weight:bold;font-family:courier;">!pwd</span><br><br>What is the pathname? Which server does this represent: local or remote?<br><br>
+
# Issue the following ''sftp command'': <span style="color:blue;font-weight:bold;font-family:courier;">lpwd</span><br><br>What is the pathname? Which server does this represent: local or remote?<br><br>
 
# Issue the following ''sftp command'' to create a directory on your remote server: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir remote</span><br><br>
 
# Issue the following ''sftp command'' to create a directory on your remote server: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir remote</span><br><br>
 
# Issue the following ''sftp command'' to confirm that the '''remote''' directory has been created in your remote server's home directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls</span><br><br>
 
# Issue the following ''sftp command'' to confirm that the '''remote''' directory has been created in your remote server's home directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls</span><br><br>
# Issue the following ''sftp command'' to change to the '''remote''' directory on your remote server:<br><span style="color:blue;font-weight:bold;font-family:courier;">cd remote</span><br><br>
+
# Issue the following ''sftp command'' to change to the '''remote''' directory on your ''remote'' server:<br><span style="color:blue;font-weight:bold;font-family:courier;">cd remote</span><br><br>
 
# Issue the '''pwd''' ''sftp command'' to confirm that you have changed to the ''remote2'' directory on your remote server.<br><br>
 
# Issue the '''pwd''' ''sftp command'' to confirm that you have changed to the ''remote2'' directory on your remote server.<br><br>
# Issue the following sftp command to change to the '''local''' directory on your local server:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd local</span><br><br>
+
# Issue the following sftp command to change to the '''local''' directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd local</span><br><br>
# Issue the '''pwd''' ''sftp command'' to confirm that you have changed to the ''local'' directory on your local server.<br><br>
+
# Issue the '''pwd''' ''sftp command'' to confirm that you have changed to the ''local'' directory on your local computer.<br><br>
 
# Issue the following ''sftp command'' to transfer your '''~/local/thefile.txt''' file to the '''~/remote''' directory on your remote server:<br><span style="color:blue;font-weight:bold;font-family:courier;">put thefile.txt</span><br><br>
 
# Issue the following ''sftp command'' to transfer your '''~/local/thefile.txt''' file to the '''~/remote''' directory on your remote server:<br><span style="color:blue;font-weight:bold;font-family:courier;">put thefile.txt</span><br><br>
# Issue the '''ls''' sftp command to confirmed that you transferred/copied the file: thefile.txt<br><br>Let's create another directory on your local server called '''local2''' so we can learn to <u>download</u> a file from your remote directory.<br><br>
+
# Issue the '''ls''' sftp command to confirmed that you transferred/copied the file: '''thefile.txt'''<br><br>Let's create another directory on your local computer called '''local2''' so we can learn to <u>download</u> a file from your remote directory.<br><br>
# Issue the following ''sftp command'' (without an argument) to change to your '''home''' directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd</span><br><br>
+
# Issue the following ''sftp command'' (without an argument) to change to your '''home''' directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd ~</span><br><br>
# Issue the '''!pwd''' ''sftp command'' to confirm that your current working directory on your local server is your home directory.<br><Br>
+
# Issue the '''lpwd''' ''sftp command'' to confirm that your current working directory on your local computer is your home directory.<br><Br>
# Issue the following ''sftp command'' to create the following directory on your local server:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir local2</span><br><br>
+
# Issue the following ''sftp command'' to create the following directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lmkdir local2</span><br><br>
# Issue the following ''sftp command'' to change to the '''local2''' directory on your local server:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd local2</span><br><br>
+
# Issue the following ''sftp command'' to change to the '''local2''' directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">lcd local2</span><br><br>
# Issue the !pwd ''sftp command'' to confirm you have changed to the ''local2'' directory on your local server.<br><br>Let's learn to download a file from your remote server to your local server.<br><br>
+
# Issue the '''lpwd''' ''sftp command'' to confirm you have changed to the ''local2'' directory on your local computer.<br><br>Let's learn to <u>download</u> a file from your remote server to your local computer.<br><br>
# Issue the following '''sftp command''' to transfer your '''thefile.txt''' file from your remote directory on your local server:<br><span style="color:blue;font-weight:bold;font-family:courier;">get thefile.txt</span><br><br>
+
# Issue the following '''sftp command''' to transfer your '''thefile.txt''' file from your remote directory on your local computer:<br><span style="color:blue;font-weight:bold;font-family:courier;">get thefile.txt</span><br><br>
# Issue the '''!ls''' '''sftp command''' to confirm that you transferred/copied the file: thefile.txt on your local server.<br><br>
+
# Issue the '''lls''' '''sftp command''' to confirm that you transferred/copied the file: thefile.txt on your local computer.<br><br>
 
# Issue the following ''sftp command'' to exit the sftp utlilty: <span style="color:blue;font-weight:bold;font-family:courier;">exit</span><br><br>
 
# Issue the following ''sftp command'' to exit the sftp utlilty: <span style="color:blue;font-weight:bold;font-family:courier;">exit</span><br><br>
# Issue the following Linux command to confirm that you are back in your original server: <span style="color:blue;font-weight:bold;font-family:courier;">hostname</span><br><br>Let's run a shell script to see if you correctly transferred/copied files between your local and remote servers.<br><br>
+
# Issue the '''ssh''' command to login to your Matrix server account.<br><br>
# Make certain that your current directory is your home directory.<br><br>
+
# Issue the following Linux command to run a checking script to ensure you created the CORRECT directories, created and copied the correct files: <br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ~uli101/week6-check-3</span><br><br>
# Issue the following Linux command to run a checking script to ensure you created the CORRECT directories, created and copied the correct files: <br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week6-check-4</span><br><br>
+
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.<br><br>
 +
 
 +
 
 +
 
 +
:Although it is important to learn how to use '''command-line sftp''' which is considered coverage for quizzes, midterm and final exam, there are '''graphical sftp applications''' available that are considered "user-friendly". The next investigation will show you how to transfer files between your local computer and your Matrix server graphically (assuming your local computer is running MS Windows).
 +
<br>
 +
 
 +
=== Graphical Application (Secure Shell) ===
 +
[[Image:graphical-sftp-application.png|thumb|right|200px|'''SSH Secure Shell Client''' has a graphical application to transfer files between computers.]]
 +
If you installed the graphical Secure Shell application in [https://wiki.cdot.senecacollege.ca/wiki/Tutorial_1:_Using_Your_Matrix_Server_Account#CONNECTING_TO_YOUR_MATRIX_ACCOUNT_FROM_A_GRAPHICAL_WINDOWS_APPLICATION TUTORIAL 1 INVESTIGATION 1], <br>you can run a '''graphical''' application from your computer desktop to transfer files between<br>your computer and your Matrix account.
 +
 
 +
Let's run the '''Secure Shell SFTP application''' to transfer files between computers.<br>This investigation assumes that your computer is a '''Windows''' machine. If you local computer<br>is '''NOT''' a ''Windows'' machine, you can <u>skip</u> this investigation.
 +
 
 +
 
 +
'''Perform the Following Steps:'''
 +
 
 +
# On your local computer, open the <span style="color:blue;font-family:courier;font-weight:bold;">NotePad</span> application to create a text file.<br><br>
 +
# Enter a few lines of text, and then click on the <b>File</b> menu and select <b>save as</b><br>(save as the filename <span style="color:blue;font-weight:bold;font-family:courier;">yourfile.txt</span> in your <span style="color:blue;font-weight:bold;font-family:courier;">local</span> directory)<br>and then <b>exit</b> the <i>Notepad</i> text editor.<br><br><table align="right"><tr valign="top"><td>[[Image:graphical-sftp-icon.png|thumb|right|110px|Double Click on SFTP to launch graphical application.]]</td><td>[[Image:sftp-connect.png|thumb|right|200px|Using Quick Connect to login to your Matrix Linux server.]]</td></table>
 +
# In your local computer's command terminal, make certain that you are in the '''local''' directory, and if not, change to that directory.<br><br>
 +
# Issue the <span style="color:blue;font-weight:bold;font-family:courier;">dir</span> command for the '''local''' directory to confirm that you created the file called '''yourfile.txt'''<br><br>
 +
# On your Windows desktop, point and '''double-click''' on the<br>'''SSH Secure file Transfer''' application icon.<br><br>
 +
# The main Secure Shell SFTP application window should appear.<br><br>'''FYI:''' This application shows files on your home computer (on the left-side) and files on your remote Matrix computer on the right-side. You will NOT see files<br>for your Matrix server since you have NOT logged into the Matrix server.<br><br>
 +
# Click the '''Quick Connect''' button located in the Secure SFTP application window.<br><br>'''NOTE:''' The Connect dialog box allows the user to specify the '''server name'''<br>and your '''account name''' to allow you to connect to the server.<br><br>
 +
# Click on the textbox labelled '''Hostname''' and type the text: <span style="color:blue;font-weight:bold">matrix.senecacollege.ca</span><br><br>
 +
# Click on the textbox labelled '''User Name''' and type your Seneca username<br>(i.e. same as your Seneca userid).<br><br>
 +
# After entering the ''hostname'' and ''username'', click the '''Connect''' button.<br><br>
 +
# Enter your Seneca password when prompted.<br><br>
 +
# When you correctly connect to your Matrix account, you should see '''folders'''<br>in your remote server (i.e. Matrix server).<br><br>[[Image:graphical-sftp-application.png|thumb|right|250px|'''Click''' and '''drag''' file(s) to transfer between computers.]]
 +
# There are two sub-windows to represent your local computer on the <u>left</u><br>and the remote (Matrix) server on the <u>right</u>.<br><br>
 +
# In the <u>left</u> (local computer) window, point and '''double-click''' on your Windows<br>profile name (i.e. ''username'') and then locate and '''double-click''' on the '''local''' directory.<br><br>
 +
# In the <u>right</u> (remote Matrix server) window, navigate to the '''remote2''' directory<br>and '''double-click''' to move to that directory.<br><br>
 +
# In the left window, click and drag the '''yourfile.txt''' file to the <u>right</u> window.<br><br>
 +
# Check to see that the '''yourfile.txt''' file appears in the <u>right</u> window to confirm<br>that the file has been transferred to your Matrix server.<br><br>'''NOTE:''' You can select multiple files by using ''SHIFT-CLICK'' or ''CTRL-CLICK'' methods<br>and then click and drag file selections between computers.<br><br>
 +
# Take a few moments to noter other buttons for both local and remote windows to<br>'''refresh the view''', '''delete file(s)''', '''navigate up to parent directory''', etc.<br><br>
 +
# Click the '''File''' menu, and select '''Disconnect''' and then click '''OK''' to disconnect your sftp connection.<br><br>
 +
# Now that you have disconnected, '''close''' the sftp application window.<br><br>
 +
# Return to your command terminal on your <u>local</u> computer (do '''NOT''' connect to Matrix!).<br><br>
 +
# Issue the following Linux command to run a checking script to confirm that you transferred<br>the most recently-created textfile to the '''remote2''' directory in Matrix:<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ~uli101/week6-check-4</span><br><br>
 +
# When prompted, enter your password.<br><br>
 
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.<br><br>
 
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.<br><br>
  
:In the next investigation, you will learn an alternative way to transfer a file to another computer server by sending an e-mail message with an attached file.
+
-->
  
=INVESTIGATION 3: USING THE MAIL COMMAND TO SEND FILE ATTACHMENTS =
+
:In the next investigation, you will learn an alternative way to transfer a file to another computer server<br>by sending an '''e-mail message with an attached file'''.
  
 +
=INVESTIGATION 3: FILE TRANSFER (EMAIL) =
  
Your '''Matrix''' server is also an '''email server''' that can allow you to send and receive text-based email messages.
 
  
 +
The '''Matrix''' server is also an '''email server''' that can allow you to '''send''' emails messages to other email accounts.
  
In this section, you will learn how to transfer a file from your Matrix server to another computer system by sending an email message with a file attachment.
+
In this investigation, you will learn how to '''transfer''' a file from your Matrix server to another computer by sending<br>an '''email message''' with a '''file attachment'''.
  
  
 
'''Perform the Following Steps:'''
 
'''Perform the Following Steps:'''
  
# Make certain that you are logged into your '''Matrix''' account and are located in your '''home''' directory.<br><br>
+
# Make certain that you connect and login to your '''Matrix''' server and confirm that you are located in your '''home''' directory.<br><br>
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mail yoursenecaid@myseneca.ca</span><br><br>
+
# Issue the following Linux command (using your Seneca-ID):<br><span style="color:blue;font-weight:bold;font-family:courier;">mail yoursenecaid@myseneca.ca</span><br><br>
# When prompted, enter the subject line:  <span style="color:blue;font-weight:bold;font-family:courier;">Test Message</span><br>and press <span style="color:blue;font-weight:bold;font-family:courier;">ENTER</SPAN><br><br>
+
# When prompted, enter the '''subject line''':  <span style="color:blue;font-weight:bold;font-family:courier;">Test Message</span><br>and press <span style="color:blue;font-weight:bold;font-family:courier;">ENTER</SPAN><br><br>
# In the email message '''BODY''' section, type the following text displayed below:<br><span style="font-weight:bold;font-family:courier;">This is a test email message</span><br><br>
+
# In the email message '''BODY''' section, type the following text displayed below (and press '''ENTER'''):<br><span style="font-weight:bold;font-family:courier;">This is a test email message</span><br><br>
# Press <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-d</span> to send your email message.<br><br>Did any output display after you sent this email message? If so, what you do think it stands for?<br><br>
+
# Press <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-d</span> to send your email message.<br><br>Did any output display? What you do think '''EOT''' stands for?<br><br>
# Launch a '''web-browser''', login into your Seneca email and check for new email messages. Did you receive the email message that you sent from your Matrix server?<br><br>If you did NOT receive an e-mail message, check the '''JUNK''' or '''CLUTTER''' folders.<br><br>
+
# Launch a '''web-browser''', login into your '''Seneca email''' account and check for new email messages.<br>Did you receive the email message that you sent from your Matrix server?<br><br>If you did NOT receive an e-mail message, check the '''JUNK''' or '''CLUTTER''' folders.<br>If you still did not receive an email message, return to your terminal and re-issue the '''mail''' command<br>making certain that you pressed <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-d</span> instead of pressing '''ctrl-c'''<br><br>
# Return to your shell and issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mail -a ~/local/thefile.txt yoursenecaid@myseneca.ca</span><br><br>
+
# Return to your terminal (i.e. Linux Bash shell) and issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mail -a ~/remote/myfile.txt yoursenecaid@myseneca.ca</span><br><br>
# When prompted, enter the subject line: <span style="font-weight:bold;font-family:courier;">Test Message with Attachment</span><br><br>
+
# When prompted, enter the subject line: <span style="color:blue;font-weight:bold;font-family:courier;">Test Message with Attachment</span><br> and press <span style="color:blue;font-weight:bold;font-family:courier;">ENTER</span><br><br>
# In the email message '''BODY''' section, type the following text displayed below:<br><span style="font-weight:bold;font-family:courier;"><br>This is a test email message with a file attachment</span><br><br>
+
# In the email message '''BODY''' section, type the following text displayed below (and press '''ENTER'''):<br><span style="font-weight:bold;font-family:courier;">This is a test email message with a file attachment</span><br><br>
 
# Press <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-d</span> to send your message.<br><br>
 
# Press <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-d</span> to send your message.<br><br>
# Switch to your email and check your Seneca email for messages. Did you receive that email message?<br><br>
+
# Switch to your Seneca email and check for new email messages.<br><br>Did you receive that email message? Does the email contain a file attachment?<br><br>
# Check your email to see if you received your email message. If you did, what do you notice?<br><br>
+
# Return to your Linux Bash shell and issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mail  yoursenecaid@myseneca.ca &lt; ~/remote/myfile.txt</span><br><br>What happened? Were you prompted for subject and could you enter text in email body?<br>Did you see a file attachment as a separate file, or just text?<br><br>
# Return to your shell and issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mail -s "email with attachment" yoursenecaid@myseneca.ca &lt; ~/local/thefile.txt</span><br><br>What happened?<br><br>
+
# Check your email to see if you received your email message. If you did, what do you notice regarding the subject line?<br><br>You should have noticed that there was '''NO''' customized '''subject line''',<br>since you redirected '''standard input''' (''stdin'') from the file, so there was no way<br>for the user to send a subject line.<br><br>You can use the '''-s''' option, followed by text (in quotes) to specify a '''subject line'''.<br><br>
# Check your email to see if you received your email message. If you did, what do you notice?<br><br>
+
# Return to your Linux Bash shell and issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mail -s "email with attachment" yoursenecaid@myseneca.ca &lt; ~/remote/myfile.txt</span><br><br>
 +
# Check your email to see if you received your email message. If you did, what do you notice this time?<br><br>
 
# After completing this INVESTIGATION, perform the LINUX PRACTICE QUESTIONS at the end of the tutorial.<br><br>
 
# After completing this INVESTIGATION, perform the LINUX PRACTICE QUESTIONS at the end of the tutorial.<br><br>
  
Line 224: Line 329:
 
simulate a quiz:
 
simulate a quiz:
  
https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week6_practice.docx
+
https://wiki.cdot.senecacollege.ca/uli101/files/uli101_week6_practice.docx
  
 
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
 
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
Line 231: Line 336:
 
'''Review Questions:'''
 
'''Review Questions:'''
  
# Write a Linux command to copy a file in the current directory called '''mytext.txt''' from your Matrix account to your account called user1 on the Linux server domain name called '''tech.myserver.com''' to that user’s home directory.
+
# Write a Linux command to copy a file in the current directory called '''mytext.txt''' from your Matrix account to your account called '''user1'''<br>on the Linux server domain name called '''tech.myserver.com''' to that user’s home directory.
 
# Write a Linux command similar to the previous question, but rename the file on the remote Linux server to '''yourtext.txt'''  
 
# Write a Linux command similar to the previous question, but rename the file on the remote Linux server to '''yourtext.txt'''  
# Write a Linux command to copy a file called '''~/project/linux.txt''' to the remote server called '''linux.techie.org'''<br>(your username for this remote server is the same username for your local server).
+
# Write a Linux command to copy a file called '''~/project/linux.txt''' to the remote server called '''linux.techie.org'''<br>(your username for this remote server is the same username for your local server).<br><br>
 
# Write a Linux command to connect to the username '''saulm''' for the server domain name '''tux.senecac.on.ca''' to transfer files between Linux servers.
 
# Write a Linux command to connect to the username '''saulm''' for the server domain name '''tux.senecac.on.ca''' to transfer files between Linux servers.
 
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to display your current working directory on your local server?
 
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to display your current working directory on your local server?
Line 239: Line 344:
 
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to <u>download</u> the file answers.txt from the current directory of your remote server?
 
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to <u>download</u> the file answers.txt from the current directory of your remote server?
 
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to <u>upload</u> the file questions.txt from your local server to the '''~/documents/tests''' directory on your remote server?
 
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to <u>upload</u> the file questions.txt from your local server to the '''~/documents/tests''' directory on your remote server?
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to quit your current session?
+
# Assuming that you are connected to that server in ''question #4''. What is the sftp command to quit your current session?<br><br>
 
# Write a Linux command to send the attached file '''message.txt''' to the email address '''murray.saul@senecacollege.ca''' with the subject line: '''Important Message'''
 
# Write a Linux command to send the attached file '''message.txt''' to the email address '''murray.saul@senecacollege.ca''' with the subject line: '''Important Message'''
 
# Create a '''table''' listing each Linux command, useful options  and command purpose for the following Linux commands: '''scp''' , '''sftp''' , '''mail'''.
 
# Create a '''table''' listing each Linux command, useful options  and command purpose for the following Linux commands: '''scp''' , '''sftp''' , '''mail'''.
# Create a '''table''' listing each '''sftp command'''and it's purpose.
+
# Create a '''table''' listing each '''sftp command''' and it's purpose.
 +
 
 +
 
 +
_________________________________________________________________________________
 +
 
 +
Author:  Murray Saul
 +
 
 +
License: LGPL version 3
 +
Link:    https://www.gnu.org/licenses/lgpl.html
 +
 
 +
_________________________________________________________________________________
 +
 
  
  
 
[[Category:ULI101]]
 
[[Category:ULI101]]

Latest revision as of 19:35, 4 September 2023

Stop (medium size).png
DO NOT USE THIS VERSION OF THE LAB. This page will no longer be updated.
New version here: https://seneca-ictoer.github.io/ULI101/A-Tutorials/tutorial6
Andrew's students please go here: http://wiki.littlesvr.ca/wiki/OPS145_Lab_6

TRANSFERRING FILES BETWEEN COMPUTERS


Main Objectives of this Practice Tutorial

  • List common utilities contained in the ssh application framework
  • Securely copy files between Unix/Linux servers using the scp command
  • Securely transfer copies of files between Unix/Linux servers using the sftp command
  • Use the ssh command to run and view commands on a remote computer from a local computer.
  • Use the mail command to send email with file attachments to your Seneca email account


Tutorial Reference Material

Course Notes
Definitions / Commands
YouTube Videos
Slides: Definitions: File Transfer Commands: Instructional Videos:

KEY CONCEPTS

The ssh Linux command is a suite of tools to allow the user to issue Linux commands securely between
Unix / Linux servers, as well as securely copy and transfer files among Unix/Linux servers.

In this tutorial, you will learn several different methods to securely transfer files from your Matrix Linux account
to other computers using Linux commands including scp, sftp and mail.


Issuing Commands on Remote Unix/Linux Servers

The ssh command can be used to run and view commands on remote computer from a local computer.

You can use the ssh command to issue Unix/Linux commands on a remote server
from your local computer without logging into a remote server (such as Matrix).


Command Usage:

ssh username@matrix.senecacollege.ca ls -l

You will be prompted for your Matrix account password, then the contents of your home directory in your remote Matrix account will be displayed on your local computer's terminal.

Secure Copy (scp)

The scp Unix/Linux command is used to securely copy files between Unix/Linux servers.

The scp command is used to securely copy files between your local computer and remote Unix/Linux server. The usage for the scp command is similar to the cp command with the addition of user name and host name.


Command Usage:

scp local.file username@host:destination-pathname
scp local.file username@host:
scp user@host:file-pathname local-pathname

The most common mistake that students make is forgetting to add
the colon character ":" after the remote hostname.

The user name in the command can be omitted if it's the same as on the local host.
Multiple file and recursive directory copy (i.e. option -r) is supported.

Secure File Transmission Control Protocol (sftp)

The sftp Unix/Linux command is used to securely transfer (copy) files between Unix/Linux servers.

FTP stands for File Transfer Protocol which provides a set of rules on how to convert data that is transferred between computers (both identical and different operating systems). The sftp command performs file transfers securely using encryption.


Command Usage:

sftp username@hostname


When you login via the sftp command, the sftp prompt appears. The sftp prompt is like a Bash shell prompt, but with a limited number of commands. When issuing sftp commands, the local server relates to the server where you first issued the sftp command. Refer to the diagram on the right for local and remote sftp commands.

Graphical SFTP application.


Graphical SFTP Applications

Although it is important to know how to use the sftp command for quizzes, midterm and final exam,
there are graphical sftp applications that provide an alternative to issuing commands.

If you installed the graphical Secure Shell Client application in your Windows computer from performing TUTORIAL 1 INVESTIGATION 1, you can use this application to transfer files between your computer and your Matrix account by graphically navigating, selecting and dragging files between computers.

Sending Emails with File Attachment (mail)

You can use the mail command in Matrix to send email messages
to other email accounts via the Internet.


Using the mail command with redirection to send email
with file attachment.

Sending a Simple Email Message:

  1. Type: mail username@hostname and press ENTER
  2. Enter subject line and press ENTER
  3. Type the body of the message and then when finished,
    press ctrl+d to send message

Sending an Email Message with a File Attachment:

Viewing email with file attachment in
Seneca email account.
  1. Type: mail username@hostname -a filepathname and press ENTER
  2. Enter subject line and press ENTER
  3. Type the body of the message and then when finished, press ctrl+d to send message

Alternative Method of Sending an Email Message with a File Attachment:

  1. Type: mail -s "subject line" username@hostname < filepathname
  2. Press ENTER to send

    NOTE: You would have to use this method since you have used stdin redirection
    to attach the file’s so you can’t input the subject line from the terminal!

INVESTIGATION 1: FILE TRANSFER (SECURE COPY)

ATTENTION: This online tutorial will be required to be completed by Friday in week 8 by midnight to obtain a grade of 2% towards this course

Make certain to open a command-line terminal and
NOT a graphic SSH application for this tutorial!.

The SSH package on your home computer and on the Matrix Linux server
contain a suite (i.e. collection) of secure utilities including ssh and scp.


In this investigation, you will learn how to use the scp command to securely copy files between your computer and your Matrix Linux server. This methods is useful because it can be performed in the MS-Windows, MacOSx, and Unix/Linux operating systems.

You will also learn how to issue the ssh command to run commands on your
remote Matrix server while remaining on your local computer.


Perform the Following Steps:

  1. Determine which operating system that your computer is using.

  2. Connect to your Matrix account using the instructions in the table below based on your current operating system.

Newer Version of Windows 10: MacOSX: Linux:
  • From the start menu, type cmd and launch program
  • In the command terminal, enter the following command:
    ssh senecausername@matrix.senecacollege.ca
  • Click Launchpad icon, type terminal
    and press ENTER
  • In the terminal, enter the following command:
    ssh senecausername@matrix.senecacollege.ca
  • From the menu, choose:
    Applications > System Tools > Terminal
  • In the terminal, enter the following command:
    ssh senecausername@matrix.senecacollege.ca

  1. NOTE: Make certain to open a command-line terminal and NOT a graphical SSH application for this tutorial.

  2. After logging into your Matrix account, issue to the pwd command to confirm you are in your home directory.

  3. Issue the following Linux command to create the following directory:
    mkdir ~/remote

  4. Change to the ~/remote directory and confirm that you have changed to that directory.

  5. Use a text editor to create a text file called myfile.txt

  6. Enter the following two lines displayed below in your editing session:
    This is my file
    It is a small file


  7. Save editing changes to your myfile.txt file and exit your text editor.

  8. Let's run a shell script to check that you created the remote directory
    and that you created the myfile.txt file (with correct file contents) in that directory.

  9. Enter the following command: ~uli101/week6-check-1

  10. If you encounter errors, make corrections and then re-run the checking script until you receive
    a congratulations message, and proceed to the next step.

    NOTE: We will now learn to transfer files between your local home computer and your remote Matrix Linux server.

You are required to remain in your local computer's command terminal for the remainder of this INVESTIGATION and INVESTIGATION 2
  1. Exit your Matrix ssh session but remain in the command terminal
    on your local computer..

    ATTENTION: You are required to remain in your local computer's command terminal for the remainder of this INVESTIGATION and INVESTIGATION 2.

  2. The mkdir command works with MS Windows/UNIX/Linux/MacOSx computers.
    Issue the following command on your local computer to
    create a directory called local: mkdir local

  3. The cd command works with MS Windows/UNIX/Linux/MacOSx computers.
    Issue the following command on your local computer to
    change to the local directory: cd local

  4. If you are using MS Windows on your local computer, issue the dir command to confirm you are
    in the local directory; otherwise, use the pwd command.

  5. If you are in MS Windows, open the GRAPHICAL NotePad application to create a text file
    (Otherwise, use the nano or vi text editor).

  6. Enter a few lines of text, and if using Notepad, then click on the File menu and select save as
    (save as the filename other.txt in your local directory) and then exit the Notepad text editor.

    NOTE: if using another text editor, save your editing session and exit the text editor.

  7. If your OS is MS Windows issue the dir Windows command to view the contents of your current directory
    (otherwise, issue the ls command for other operating systems).

    We will use the scp command to copy the local file called other.txt to your home directory on your remote Matrix Linux server.

  8. Issue the following Linux command to copy the other.txt file from your local machine to your remote Matrix server
    (replace yoursenecaid is YOUR Seneca ID and ADD A COLON : TO THE END OF THE COMMAND):
    scp other.txt yoursenecaid@matrix.senecacollege.ca:

  9. When prompted, enter your Matrix password.
    You can issue the ssh command, followed by a command that will be run on your remote computer,
    but display command output on your local computer.

    TIP: You can issue the ssh command, followed by a command that will be run on your remote computer, but display on your local computer without having to establish a continuous connection to your remote Matrix server.

  10. Issue the following command (using your matrix username):
    ssh yoursenecaid@matrix.senecacollege.ca ls -l other.txt

  11. When prompted, enter your password and press ENTER.

    Do you see detailed information other.txt file? (look at bottom)
    That command was run remotely on your Matrix server as confirmation that you securely copied that file to the home directory of the Matrix server.

    Let's copy the file called myfile.txt in the ~/remote directory that you created earlier in your Matrix account to your local directory on your home computer.

  12. Issue the following Linux command (replace yoursenecaid is YOUR Seneca ID).
    The period "." as second argument represents your current directory
    on your local computer):
    scp yoursenecaid@matrix.senecacollege.ca:remote/myfile.txt .

  13. Issue the dir or ls command (depending on the OS of your local computer) to confirmed your properly copied that file from Matrix.

  14. Use the Notepad application (or vi for other OS types) to create a text file called mytextfile.txt,
    type some text and then save in the local directory of your computer.

  15. Issue the dir or ls command (depending on your OS) to confirm that your newly-created file exists in your local directory.

  16. We are going to intentionally make a mistake with the scp command.
    Issue the following Linux command to copy the mytextfile.txt file from your local machine to your remote Matrix server
    (replace yoursenecaid is YOUR Seneca ID and DO NOT INCLUDE THE : at the end of the command so see what happens):
    scp mytextfile.txt yoursenecaid@matrix.senecacollege.ca

    Did you notice anything different (i.e. no password)?

  17. Issue the following command (using your matrix username):
    ssh yoursenecaid@matrix.senecacollege.ca ls -l mytextfile.txt

  18. When prompted, enter your password and press ENTER.

    The file mytextfile.txt does NOT appear in your home directory on your Matrix server!
    Note that the COLON was NOT added to the end of the command! Therefore, you MUST
    remember to include the COLON : at the end of the hostname, or it will NOT remotely copy the file!


  19. Issue the following command to properly copy that same file to your Matrix server:
    scp mytextfile.txt yoursenecaid@matrix.senecacollege.ca:

  20. Issue the following command to confirm that it was remotely copied to your home directory in Matrix:
    ssh yoursenecaid@matrix.senecacollege.ca ls -l /home/yoursenecaid/mytextfile.txt

    Do you see the output for the detailed file listing of mytextfile.txt?
    What does this indicate?

  21. Issue the following command to copy the other.txt file on your local computer to the ~/remote directory in Matrix renaming it as different.txt:
    scp other.txt yoursenecaid@matrix.senecacollege.ca:remote/different.txt

  22. Issue the following command to confirm that the file was remotely copied to your ~/remote directory in Matrix with a different filename:
    ssh yoursenecaid@matrix.senecacollege.ca ls -l /home/yoursenecaid/remote/different.txt

    Were you able to properly copy this file?

    Let's issue a checking script remotely to see that you properly copied that file from your
    local computer to your remote Linux server to both your home directory and ~/remote directory.

  23. Issue the following:
    ssh yoursenecaid@matrix.senecacollege.ca ~uli101/week6-check-2

    If you encounter errors, re-run the scp commands to correct and re-run the above command until you receive a congratulations message.

  24. Remain in the terminal on your local computer and proceed to INVESTIGATION 2.

In the next investigation, you will use the sftp Linux command to transfer (i.e. copy) files between your local computer and the Matrix server.


INVESTIGATION 2: FILE TRANSFER (SECURE FTP)

The SSH package on your home computer and on the Matrix Linux server
contain a suite (i.e. collection)of secure utilities including ssh and sftp.


In this investigation, you will learn how to use the sftp command to transfer files between
Unix/Linux servers. This methods is useful because it can be performed in the
MS-Windows, MacOSx, and Unix/Linux operating systems.

You will also learn how to issue the ssh command to run commands on your
remote Matrix server while remaining on your local computer.


Command Line Terminal (CLI)

Let's look at using the sftp command on your local machine.


Perform the Following Steps:

Make certain to remain in the
command-line terminal in your local computer.
  1. Make certain that you are in a command terminal on your local computer
    (i.e. do NOT log into your Matrix account).

  2. Issue a command (depending on your OS) to confirm that you are located in the local directory in your home computer.

  3. If you are in MS Windows, open the NotePad application to create a text file
    (otherwise: use another text editor like vi or nano)
    .
  4. Enter a few lines of text, and then click on the File menu and select save as
    (save as the filename thefile.txt in your local directory) and then exit the Notepad text editor.

    If you using another OS, then save-as using the same filename and directory location for the text editor you are using.

  5. If your OS is MS Windows issue the dir Windows command to view the contents of your current directory
    (otherwise, issue the ls command for other operating systems).

    Note: the relative pathname symbols "." and ".." work for the Windows/MacOSx/Unix/Linux operating systems.

  6. Issue the following command to move to the parent directory: cd ..

  7. If your OS is MS Windows issue the dir Windows command to view the contents of that parent directory that you changed to
    (otherwise, issue the ls command for other operating systems).

  8. Issue the following command to start an sftp session (note: yoursenecaid is YOUR Seneca ID):
    sftp yoursenecaid@matrix.senecacollege.ca

    NOTE: You may be required to enter yes to have the public key shared.

    Common sftp commands to manage the transfer
    of files between computers.
  9. You should be in the sftp command prompt where you are expected to issue sftp commands. Please take a moment to view common
    local and remote sftp commands on the right-side table.

  10. Issue the following sftp command: pwd

    What is the pathname? Which server does this represent: local or remote?

  11. Issue the following sftp command: lpwd

    What is the pathname? Which server does this represent: local or remote?

  12. Issue the following sftp command to create a directory on your remote server: mkdir remote2

  13. Issue the following sftp command to confirm that the remote2 directory has been created
    in your remote server's home directory:
    ls

  14. Issue the following sftp command to change to the remote2 directory on your remote server:
    cd remote2

  15. Issue the pwd sftp command to confirm that you have changed to the remote2 directory on your remote server.

  16. Issue the following sftp command to change to the local directory on your local computer:
    lcd local

  17. Issue the lpwd sftp command to confirm that you have changed to the local directory on your local computer.

  18. Issue the following sftp command to transfer the file called thefile.txt to the ~/remote2 directory on your remote server:
    put thefile.txt

  19. Issue the ls sftp command to confirmed that you transferred the file called: thefile.txt

    Let's create another directory on your local computer called local2 so we can learn to download a file from your remote directory.

  20. Issue the following sftp command to change to the parent directory on your local computer:
    lcd ..

  21. Issue the lpwd sftp command to confirm that your current working directory on your local computer is your home directory.

  22. Issue the following sftp command to create the following directory on your local computer:
    lmkdir local2

  23. Issue the following sftp command to change to the local2 directory on your local computer:
    lcd local2

  24. Issue the lpwd sftp command to confirm you have changed to the local2 directory on your local computer.

    Let's learn to download a file from your remote server to your local computer.

  25. Issue the following sftp command to transfer your thefile.txt file from the remote2 directory
    on your remote server to your local computer:
    get thefile.txt

  26. Issue the lls sftp command to confirm that you transferred the file thefile.txt to your local computer.

  27. Issue the following sftp command to exit the sftp utlilty: exit

  28. Issue the following Linux command to remotely run a checking script to ensure you created the correct directories
    and properly transferred those created files:
    ssh yoursenecaid@matrix.senecacollege.ca ~uli101/week6-check-3

  29. If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.

    FYI: To run a checking program to check if you created the local and local2 directories in MS Windows would require
    running a local-based script (like PowerShell). Since this is a Unix/Linux based course, we don't have a PowerShell script,
    so we will ignore checking for files transferred to your local computer.


In the next investigation, you will learn an alternative way to transfer a file to another computer server
by sending an e-mail message with an attached file.

INVESTIGATION 3: FILE TRANSFER (EMAIL)

The Matrix server is also an email server that can allow you to send emails messages to other email accounts.

In this investigation, you will learn how to transfer a file from your Matrix server to another computer by sending
an email message with a file attachment.


Perform the Following Steps:

  1. Make certain that you connect and login to your Matrix server and confirm that you are located in your home directory.

  2. Issue the following Linux command (using your Seneca-ID):
    mail yoursenecaid@myseneca.ca

  3. When prompted, enter the subject line: Test Message
    and press ENTER

  4. In the email message BODY section, type the following text displayed below (and press ENTER):
    This is a test email message

  5. Press ctrl-d to send your email message.

    Did any output display? What you do think EOT stands for?

  6. Launch a web-browser, login into your Seneca email account and check for new email messages.
    Did you receive the email message that you sent from your Matrix server?

    If you did NOT receive an e-mail message, check the JUNK or CLUTTER folders.
    If you still did not receive an email message, return to your terminal and re-issue the mail command
    making certain that you pressed ctrl-d instead of pressing ctrl-c

  7. Return to your terminal (i.e. Linux Bash shell) and issue the following Linux command:
    mail -a ~/remote/myfile.txt yoursenecaid@myseneca.ca

  8. When prompted, enter the subject line: Test Message with Attachment
    and press ENTER

  9. In the email message BODY section, type the following text displayed below (and press ENTER):
    This is a test email message with a file attachment

  10. Press ctrl-d to send your message.

  11. Switch to your Seneca email and check for new email messages.

    Did you receive that email message? Does the email contain a file attachment?

  12. Return to your Linux Bash shell and issue the following Linux command:
    mail yoursenecaid@myseneca.ca < ~/remote/myfile.txt

    What happened? Were you prompted for subject and could you enter text in email body?
    Did you see a file attachment as a separate file, or just text?

  13. Check your email to see if you received your email message. If you did, what do you notice regarding the subject line?

    You should have noticed that there was NO customized subject line,
    since you redirected standard input (stdin) from the file, so there was no way
    for the user to send a subject line.

    You can use the -s option, followed by text (in quotes) to specify a subject line.

  14. Return to your Linux Bash shell and issue the following Linux command:
    mail -s "email with attachment" yoursenecaid@myseneca.ca < ~/remote/myfile.txt

  15. Check your email to see if you received your email message. If you did, what do you notice this time?

  16. After completing this INVESTIGATION, perform the LINUX PRACTICE QUESTIONS at the end of the tutorial.

LINUX PRACTICE QUESTIONS

The purpose of this section is to obtain extra practice to help with quizzes, your midterm, and your final exam.

Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to simulate a quiz:

https://wiki.cdot.senecacollege.ca/uli101/files/uli101_week6_practice.docx

Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).


Review Questions:

  1. Write a Linux command to copy a file in the current directory called mytext.txt from your Matrix account to your account called user1
    on the Linux server domain name called tech.myserver.com to that user’s home directory.
  2. Write a Linux command similar to the previous question, but rename the file on the remote Linux server to yourtext.txt
  3. Write a Linux command to copy a file called ~/project/linux.txt to the remote server called linux.techie.org
    (your username for this remote server is the same username for your local server).

  4. Write a Linux command to connect to the username saulm for the server domain name tux.senecac.on.ca to transfer files between Linux servers.
  5. Assuming that you are connected to that server in question #4. What is the sftp command to display your current working directory on your local server?
  6. Assuming that you are connected to that server in question #4. What is the sftp command to view files in your local server?
    What is the sftp command to view files in your remote server?
  7. Assuming that you are connected to that server in question #4. What is the sftp command to download the file answers.txt from the current directory of your remote server?
  8. Assuming that you are connected to that server in question #4. What is the sftp command to upload the file questions.txt from your local server to the ~/documents/tests directory on your remote server?
  9. Assuming that you are connected to that server in question #4. What is the sftp command to quit your current session?

  10. Write a Linux command to send the attached file message.txt to the email address murray.saul@senecacollege.ca with the subject line: Important Message
  11. Create a table listing each Linux command, useful options and command purpose for the following Linux commands: scp , sftp , mail.
  12. Create a table listing each sftp command and it's purpose.


_________________________________________________________________________________

Author: Murray Saul

License: LGPL version 3 Link: https://www.gnu.org/licenses/lgpl.html

_________________________________________________________________________________