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>
:* Securely '''transfer''' copies of files between Unix/Linux servers using the '''sftp''' command
:* Use the '''mailssh''' command to send email messages to your Seneca email accountrun 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
|- 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>
|}
= KEY CONCEPTS =
The '''ssh''' Linux command is a '''suite of tools''' to allow the user to issue Linux commandssecurely between <br>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<br>to other computers using Linux commands including '''scp''', '''sftp''' and '''mail'''.
===Issuing Commands on Remote Unix/Linux Servers===
[[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).
''ExampleCommand Usage:''
<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<Br>in your remote Matrix account will be displayed, although you will remain on your <u>local </u> computer's terminal.
<br><br>
===Secure Copy (scp)===
[[Image:scp-diagram.png|thumb|right|450px350px|The '''scp''' Unix/Linux command is used to securely copy files between Unix/Linux servers.]]''Secure copy protocol (The '''scp''') command is a means of used to <u>securely transferring computer </u> copy files between a your '''local host ''' computer and a '''remote host or between two remote hosts''' Unix/Linux server. It The usage for the ''scp'' command is based on similar to the Secure Shell (SSH) protocol. "SCP" commonly refers to both '''cp''' command with the Secure Copy Protocol addition of '''user name''' and the program itself.'''host name'''.
''Command Usage:''
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>
[[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-family:courier">sftp username@hostname</span>'''
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.]]
'''<big>Graphical SFTP Applications</big>'''
Although it is important to learn know how to use the '''sftp''' command-line sftp and is considered coverage<br>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],<br>you can run a graphical use this application from to transfer files between your computer desktopand your Matrix account by graphically '''navigating''', '''selecting''' and '''dragging''' files between computers.<br><br>
===Sending Emails with File Attachment (mail)===
You can use the '''<span style="font-weight:bold;">mail''' command in Matrix to send email messages</spanbr> is a command-line to other email client for Unix and Unix-like operating systemsaccounts via the Internet.''
[[Image:mail-diagram.png|thumb|right|250px400px|The Using the '''mail''' command allows users with '''redirection''' to send and receive email messages. (Image licensed under [https://creativecommons.org/licenses/by-sa/3<br>with file attachment.0/ cc])]]
'''Sending a Simple Email Message:'''
:#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>
'''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>
'''Alternative Method of Sending an Email Message with a File Attachment:'''
:#Type: '''<span style="font-family:courier;">mail -s "your subject line" username@hostname < filenamepathnamefilepathname</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>
=INVESTIGATION 1: USING 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<br>and your Matrix Linux server. 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 a command commands on your<br><u>'''remote'''</u> Matrix server while remaining on your <u>'''local '''</u> computer.
</td>
</tr>
</table><br><br><ol><li value="3">After logging into your Matrix account, issue the following Linux commands '''NOTE:''' Make certain to create the following directory:<br>open a '''command-line terminal''' and <span style="color:blue;font-weight:bold;font-family:courier;"u>mkdir ~/remoteNOT</spanu>a <u>graphical</u> SSH application for this tutorial.<br><br></li><li>Change After logging into your Matrix account, issue to the <b>~/remote</b> directory and '''pwd''' command to confirm that you have changed to that are in your home directory.<br><br></li><li>Use a text editor Issue the following Linux command to create a text file called the following directory:<bbr>myfile.txt<span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/remote</bspan><br><br></li><li>Enter Change to the following two lines displayed below in your editing session:<b>~/remote</b> directory and confirm that you have changed to that directory.<br><br><span style="font-family:courier;font-weight:bold;"/li>This is my file<brli>It is Use a text editor to create a small text filecalled </spanb><br><br></li><li><b>Savemyfile.txt</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 Enter the correct directoriesfollowing two lines displayed below in your editing session:<br>and that you created the <bspan style="font-family:courier;font-weight:bold;">myfile.txtThis is my file</bbr> It is a small file (with correct file contents) in the <b>~/from</b> directory<br</span>before using the ''scp'' Linux command.<br><br></li></li>Enter the following command: <span style="color:blue;font-weight:bold;font-family:courier;"b>bash /home/murray.saul/scripts/week6-check-1Save</spanb>editing changes to your ''myfile.txt'' file and exit your text editor.<br><br></li><li>If you encounter errors, make corrections and then re-Let's run the checking a <b>shell script until you receive<br/b>a congratulations message, and proceed to check that you created the next step.<brb>remote</b>directory<br>and that you created the <b>NOTE:myfile.txt</b> We will now learn to transfer files between your <b>file (localwith correct file contents) home computerin that directory.</bbr> and your <bbr>(remote) Matrix Linux server<</b>.<br><brli></li>Enter the following command: <li>'''Exit your Matrix ssh session'''.span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week6-check-1</span><br><br><span style="color:blue;"/li>'''ATTENTION:''' You are <uli>REQUIRED</u> to open a terminal on your If you encounter errors, make corrections and then re-run the checking script until you receive<ubr>local</u> (Windows/MacOSx/Linux) computera congratulations message, and proceed to the next step.<br>Do <u>'''NOT'''</u> use the ''ssh'' command to connect to your Matrix account.<br><brb>NOTE:</lib> We will now learn to transfer files between your <b><liu>local</u>The home computer</b>mkdirand your </b> command works with <iu>MS Windows/UNIXremote</u> Matrix Linux/MacOSx computersserver</ib>.<br>Issue the following command on your <ubr>local</u> computer to create a directory called <bli>local</bol>[[Image: <span style="color:blue;font-family:courier;font-weight:bold;"cmd.png|thumb|right|350px|You are required to <u>mkdir local'''remain'''</spanu>in your '''local''' computer's command terminal for the remainder of this ''INVESTIGATION'' and ''INVESTIGATION 2'']]<brol><br></livalue="12">'''Exit your Matrix ssh session''' but '''<liu>The <b>cdremain</bu> ''' in the ''command works with terminal''<ibr>MS Windows/UNIX/Linux/MacOSx computerson your '''local''' computer..</ibr>.<br>Issue the following command on your <u>local</u> computer to change to the <b>local</b> directory: <span <span style="color:blue;font-family:courier;font-weight:bold;"">'''ATTENTION:''' You are required to <u>cd local'''remain'''</span><bru> in your '''local''' computer's command terminal for the remainder of this ''INVESTIGATION'' and ''INVESTIGATION 2''.</span><br><br></li><li>If you are using The <b>mkdir</b> command works with <i>MS Windows on your local computer, issue the /UNIX/Linux/MacOSx computers<span style="color:blue;font-weight:bold;font-family:courier;"/i>dir.</spanbr> Issue the following command to confirm you areon your <bru>local</u> computer to<br>create a directory called <b>in the ''local'' directory; otherwise, use the </b>: <span style="color:blue;font-weightfamily:boldcourier;font-familyweight:courierbold;">ls -ldmkdir local</span> command.<br><br></li> <li>If you are in The <b>cd</b> command works with <i>MS Windows, open the <span style="color:blue;font-family:courier;font-weight:bold;">NotePad/UNIX/Linux/MacOSx computers</spani> application to create a text file.<br>Issue the following command on your <u>local</u> computer to<br>change to the <b>NOTE:local</b> if you are using a Graphical Linux or MacOSx OS, then use a text editor like directory: <span style="color:blue;font-family:courier;font-weight:bold;">cd local<b/span>vi</bbr><br>.</li><li>Enter a few lines of text, and if If you are using '''Notepad'''MS Windows on your local computer, then click on issue the <b>File</bspan style="color:blue;font-weight:bold;font-family:courier;"> menu and select <b>save asdir</bspan>command to confirm you are<br>(save as in the filename <b>other.txt</b> in your <b>''local</b> '' directory) and then ; otherwise, use the <bspan style="color:blue;font-weight:bold;font-family:courier;">exitpwd</bspan> command.<br> the <ibr>Notepad</ili> text editor.<brli><br>OtherwiseIf you are in MS Windows, 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 open the '''GRAPHICAL''' <span style="color:blue;font-family:courier;font-weight:bold;">dirNotePad</span> Windows command application to view the contents of your current directory<create a text file<br>(otherwiseOtherwise, issue use the <span style="color:blue;font-family:courier;font-weight:bold;"b>lsnano</spanb> command for other operating systemsor <b>vi</b> text editor).<br><br>We will now use the scp command to copy the <u/li>local</uli> file called 'Enter a few lines of text, and if using '''other.txtNotepad''' to your home directory , then click on your the <ub>remoteFile</ub> Matrix Linux server.menu and select <brb><br></li><li>Issue the following Linux command to copy the <b>other.txtsave as</b> file from your local machine to your remote Matrix server<br>(replace yoursenecaid is save as the filename <uspan style="color:blue;font-weight:bold;font-family:courier;">YOURother.txt</u> Seneca ID and '''ADD A COLON : TO THE END OF THE COMMAND'''):<brspan>in your <span style="color:blue;font-weight:bold;font-family:courier;">scp other.txt yoursenecaid@matrix.senecacollege.ca:local</span> directory) and then <b>exit</spanb>the <bri>Notepad<br/i>text editor.</libr><libr>When prompted, enter your Matrix '''password'NOTE:'''if using another text editor, save your editing session and exit the text editor.<br><br><b/li>TIP:</bli> You can issue If your OS is MS Windows issue the ssh command, followed by a command that will be run on your remote computer,<br>but displayed on your local computer <bspan style="color:blue;font-family:courier;font-weight:bold;"><u>withoutdir</uspan>Windows command to view the contents of your current directory</bbr> having to establish a continuous connection to your remote Matrix server.(otherwise, issue the <br><br></li><li>Issue the following command (using your matrix username)span style="color:blue;font-family: <span style="color:bluecourier;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l other.txt<</span>command for other operating systems).<br><br></li><li>When prompted, We will use the '''enter your passwordscp''' and press command to copy the <u>local</u> file called '''ENTERother.txt'''to your home directory on your <u>remote</u> Matrix Linux server.<br><br>Do you see detailed information regarding </li><li>Issue the following Linux command to copy the file called <b>other.txt</b>?file from your local machine to your remote Matrix server<br>That command was run remotely on your Matrix server as confirmation that you securely copied that file(replace yoursenecaid is <br>to the home directory of the Matrix server.<br><bru>YOUR</liu><li>Use the Seneca ID and '''NotepadADD A COLON : TO THE END OF THE COMMAND''' application (or vi for other OS types) to create a text file called '''mytextfile:<br><span style="color:blue;font-weight:bold;font-family:courier;">scp other.txt'''<bryoursenecaid@matrix.senecacollege.ca:</span>and save in the '''local''' directory of your computer.<br><br></li><li>Issue the following Linux command to copy the <b>mytextfileWhen prompted, enter your Matrix '''password'''.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 [[Image:scp-diagram-2.png|thumb|right|350px|You can issue the ssh command so see what happens):, followed by a '''command''' that will be run on your '''remote''' computer,<br>but <u>display<span style="color:blue;font-weight:bold;font-family:courier;">scp mytextfile.txt yoursenecaid@matrix.senecacollege.ca</spanu>command output on your '''local''' computer.]]<br><br>Did you notice anything different?<br><brb>TIP:</lib><li>Issue You can issue the following ssh command, followed by a command (using that will be run on your remote computer, but display on your matrix username): local computer <b><span style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l mytextfile.txtu>without</spanu><br/b> having to establish a continuous connection to your remote Matrix server.<br><br></li><li>When prompted, enter Issue the following command (using your password and press ENTER.matrix username):<br><brspan style="color:blue;font-weight:bold;font-family:courier;">ssh yoursenecaid@matrix.senecacollege.ca ls -l other.txt</span><br>Do you see the file? That is because the COLON was NOT added to the end of the command!<br><b/li><li>ThereforeWhen prompted, you MUST remember to include the COLON : at the end of the hostname, or it will NOT properly remotely copy the file!'''enter your password''' and press '''ENTER'''.</bbr><br>Do you see detailed information <brb>other.txt</lib>file? (look at bottom)<libr>Issue the following That command to copy was run remotely on your Matrix server as confirmation that you securely copied that same file to the ~/remote home directory in of the Matrix:server.<br><span style="color:blue;font-weight:bold;font-family:courier;">scp otherbr>Let's copy the file called '''myfile.txt yoursenecaid@matrix.senecacollege.ca:''' in the '''~/remote''' directory that you created earlier in your Matrix account to your <b>local</spanb>directory on your home computer.<br><br></li><li>Issue the following Linux command to confirm that it was remotely copied to your (replace yoursenecaid is <u>YOUR</u> Seneca ID).<br> The period "." as '''~/remotesecond argument''' directory in Matrix:represents your <u>current</u> directory<br>on your <u>local</u> computer):<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh scp yoursenecaid@matrix.senecacollege.ca ls -l :remote/home/yoursenecaid/remotemyfile.txt .</span><br><br>Do you see the output for the detailed file listing of <b>output.txt</bli>?<brli>What does this indicate?Issue the <brspan style="color:blue;font-weight:bold;font-family:courier;">dir<br/span>or <li>Issue the following span style="color:blue;font-weight:bold;font-family:courier;">ls</span> command to copy (depending on the '''otherOS of your <u>local</u> computer) to confirmed your properly copied that file from Matrix.txt<br><br></li><li>Use the '''Notepad' file to the ~/remote directory in Matrix renaming it is '''different.txt''':<br>application (or vi for other OS types) to create a text file called <span style="color:blue;font-weight:bold;font-family:courier;">scp other.txt yoursenecaid@matrix.senecacollege.ca:remote/differentmytextfile.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><br></li><li>Issue the following <b>dir</b> or <b>ls</b> command (depending on your OS) to confirm that the your newly-created file was remotely copied to exists in your '''~<b>local</b> directory.<br><br></remoteli><li>We are going to intentionally make a ''' directory in Matrix with a different filename:<bru>mistake<span style="color:blue;font-weight:bold;font-family:courier;"/u>ssh yoursenecaid@matrix.senecacollege.ca ls -l /home/yoursenecaid/remote/different''' with the '''scp''' command.txt</span><br>Issue the following Linux command to copy the <brb>What does this indicate?mytextfile.txt<br/b><br>Let's issue a checking script remotely to see that you properly copied that file from your<br>local computer machine to your remote Linux Matrix server to both your <bbr>(replace yoursenecaid is <u>homeYOUR</bu> directory Seneca ID and DO <bu>~/remoteNOT</bu> directory.<br><br></li><li>Issue INCLUDE THE : at the end of the followingcommand so see what happens):<br><span style="color:blue;font-weight:bold;font-family:courier;">ssh scp mytextfile.txt yoursenecaid@matrix.senecacollege.ca bash /home/murray.saul/scripts/week6-check-2</span><br><br>If you encounter errors, re-run the scp commands <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 correct and re-run the above command until you receive a congratulations message.<br><br></li><li>Remain in the terminal on your local computer for the ''INVESTIGATION 2''.<br><br></ol> :'''NOTE:''' It would be possible to use the '''scp''' command to copy files from the Matrix server to your Windows computer,<br>but this would require obtaining your computer's IP address and your Windows username, so we will not demonstrate this in our tutorial.
:In the next investigation, you will use the '''sftp''' Linux command to transfer (i.e. copy) files between serversyour local computer and the Matrix server.<br><br>
<!-- RESIDUAL FROM LESS EFFECTIVE METHOD OF COPYING FILES BETWEEN SERVERS
# '''Save''' editing changes to this startup file and exit your text editor.<br><br> -->
=INVESTIGATION 2: USING 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'''.
In this sectioninvestigation, you will learn how to use the '''sftp''' command to '''transfer ''' files between <br>Unix/Linux servers.<br>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.
=== Command Line Terminal (CLI) === Let's look at using the '''sftp''' command on your '''local''' machine.
'''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''' in log into your Matrix account).<br><br># Issue a command (Windows or Linuxdepending 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><br>(otherwise: use another text editor like <b>NOTE:vi</b> if you are using a Graphical Linux or MacOSx OS, then use a text editor like <b>vinano)</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 <bspan style="color:blue;font-weight:bold;font-family:courier;">thefile.txt</bspan> in your <bspan style="color:blue;font-weight:bold;font-family:courier;">local</bspan> 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 your current that parent directorythat 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'''.<br>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 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 servercomputer:<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 servercomputer.<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/copied the filecalled: '''thefile.txt'''<br><br>Let's create another directory on your local server 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 the '''parent ''' directoryon 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 server computer is your home directory.<br><Br># Issue the following ''sftp command'' to create the following directory on your local servercomputer:<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 servercomputer:<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 servercomputer.<br><br>Let's learn to <u>download</u> a file from your remote server to your local servercomputer.<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/copied the file: '''thefile.txt on ''' to your local servercomputer.<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 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 following sftp command to change to the '''local''' directory on your local servercomputer:<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 servercomputer.<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 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 '''lpwd''' ''sftp command'' to confirm that your current working directory on your local server computer is your home directory.<br><Br># Issue the following ''sftp command'' to create the following directory on your local servercomputer:<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 servercomputer:<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 servercomputer.<br><br>Let's learn to <u>download</u> a file from your remote server to your local servercomputer.<br><br># Issue the following '''sftp command''' to transfer your '''thefile.txt''' file from your remote directory on your local servercomputer:<br><span style="color:blue;font-weight:bold;font-family:courier;">get thefile.txt</span><br><br># Issue the '''lls''' '''sftp command''' to confirm that you transferred/copied the file: thefile.txt on your local servercomputer.<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>
=== Using Graphical Application (Secure Shell sftp Application in MS Windows (Graphical) ===[[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 desktopto 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 soyou local computer<br>is '''NOT''' a ''Windows'' machine, you can <u>skip </u> this sectioninvestigation.
'''Perform the Following Steps:'''
# Open 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><b>NOTE:</b> if you are using a Graphical Linux or MacOSx OS, then use a text editor like <b>vi</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 <bspan style="color:blue;font-weight:bold;font-family:courier;">yourfile.txt</bspan> in your <bspan style="color:blue;font-weight:bold;font-family:courier;">local</bspan> 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 occurNOT see files<br>for your Matrix server since you have NOT logged into the Matrix server.<br><br># Click on the '''Quick Connect''' buttonlocated 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<br>(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, navigate to 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># Confirm Check to see that the '''yourfile.txt''' file appears in the <u>right </u> window to confirm <br>that the file was has been transferredto 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 see 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''' button and exit then click '''OK''' to disconnect your sftp connection.<br><br># Now that you have disconnected, '''close''' the Secure SFTP sftp applicationwindow.<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>
-->
: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'''.<br><br>
=INVESTIGATION 3: USING THE MAIL COMMAND TO SEND FILE ATTACHMENTS TRANSFER (EMAIL) =
In this sectioninvestigation, you will learn how to '''transfer ''' a file from your Matrix server to another computer systemby sending<br>by sending an '''email message ''' with a '''file attachment'''.
'''Perform the Following Steps:'''
# Make certain that you are logged into connect and login to your '''Matrix''' account server and confirm that you are located in your '''home''' directory.<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>
# 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 What you do think it '''EOT''' stands for?<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 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 ~/localremote/thefilemyfile.txt yoursenecaid@myseneca.ca</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(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 your Seneca for new email for 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 < ~/localremote/thefilemyfile.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 noticeregarding 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>thus there was no ability 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 < ~/localremote/thefilemyfile.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]]