1,234
edits
Changes
no edit summary
{{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>
|- valign="top" style="padding-left:15px;"
|colspan="2" |Course Notes'''Slides:'''<ul><li>Week 6 Lecture 1 Notes:<br>[https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101slides/ULI101-Week66.1.pdf PDF] | [https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101slides/ULI101-Week66.1.pptx PPTX]</li></ul>
| style="padding-left:15px;" |'''Definitions:'''
* [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/Mail_(Unix) Email]<br><br>
| 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/sftp.1.html sftp]
* [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>
|}
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 <u>local</u> host.<br>Multiple file and recursive directory copy (i.e. option '''-Rr''') is supported.
<br><br>
=INVESTIGATION 1: FILE TRANSFER (SECURE COPY)=
<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>
[[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'''.
In this sectioninvestigation, 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.
</tr>
</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;">bash /home/murray.saul/scripts~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 bash /home/murray.saul/scripts~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>
In this sectioninvestigation, 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.
# 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>
<!-- OLDER CONTENT
# '''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>
# 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~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 ''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'' to exit the sftp utlilty: <span style="color:blue;font-weight:bold;font-family:courier;">exit</span><br><br>
# Issue the '''ssh''' command to login to your Matrix server account.<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 bash /home/murray.saul/scripts~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>
<br>
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 section 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 sectioninvestigation.
# 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 bash /home/murray.saul/scripts~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>
-->
: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) =
In this sectioninvestigation, 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'''.
# 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>
# Switch to your Seneca email and check for new email messages. Did you receive that email message?<br><br># Check your email to see if Did you received your receive that email message. If you did, what do you notice? Does the email contain a file attachment?<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 < ~/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># 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, thus 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># 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 < ~/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>
simulate a quiz:
https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101files/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).
# 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 '''sftp command'''and it's purpose. _________________________________________________________________________________ Author: Murray Saul License: LGPL version 3Link: https://www.gnu.org/licenses/lgpl.html _________________________________________________________________________________
[[Category:ULI101]]