"Linux Discovery Tour" Part IV lesson Three: file transfer, dashing sync

Source: Internet
Author: User
Tags ftp commands ftp login file transfer protocol ftp protocol rsync scp command secure copy man rsync

650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypqzhk6qgj6c3gjnickas5jrod5smabz5pwxwhhwoqe8jfpvf0g4adclapk24ay4zdenakcujbn8cw/0?wx_fmt=jpeg "alt=" 0 ? wx_fmt=jpeg "/>

Content Introduction

1 , < Span style= "padding:0px;margin:0px;" > Part Three: File transfer, dashing synchronization

2, The fourth part of the lesson four: analysis of the network , isolation of fire


file transfer, dashing sync


The content of this lesson is relatively simple, so we enjoy it slowly.


After learning from the previous lesson, we already know how to connect to other computers remotely. From now on, you can run commands on your computer to control the other computer in the distance, cool.


We continue to explore the fantasy web world of Linux. This network world is special, perhaps you have already realized: The predecessors have done a lot of efforts, rely on encryption method to ensure the security of data transmission between the network, in case of our private information leakage, such as password.


In this lesson, we will study file transfer, which is mainly divided into the following aspects:


    • How to download a file

    • How to connect to FTP, read, download files

    • How to copy files securely


The knowledge about the Web, which is covered in this article, can be found in the series of tutorials that have been completed: http://blog.csdn.net/column/details/webexplore.html


wget: Download file


Let's start with a simple command: wget


It allows us to download files directly from the terminal console, only the HTTP or FTP address of the file is required.


Command format:


wget [parameters] [URL address]


For example:


wget Http://cdimage.debian.org/debian-cd/8.2.0/i386/iso-cd/debian-8.2.0-i386-netinst.iso


will start to download Debian-8.2.0-i386-netinst.iso this file from http://cdimage.debian.org/debian-cd/8.2.0/i386/iso-cd/.


If you want to stop the download, just press CTRL +C


You can see a progress bar below that shows the download progress:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymaqnuioqmzu7vdrwl8xn3ub8diobiacibwxahphx725wptugp2i1oolj90gxqgaegwocvpxtd6xnug/0?wx_fmt=jpeg "alt=" 0?wx_fmt=jpeg "/>


38% indicates that 38 has been downloaded.

117K/S is the download speed, which represents 117kb per second.

ETA is the estimated time remaining, here is 70 seconds.


So, how do you get an address for wget download in advance?


You can use the browser (such as Firefox), find the file to download, and then click on the file right mouse button, left click "Copy link Address", such as:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymaqnuioqmzu7vdrwl8xn3uxbn05ibyahuncwo2emfu3ia4kp9kz7qdef9deldchdwodukyh9npoy7q/0?wx_fmt=jpeg "alt=" 0?wx_fmt=jpeg "/>


Then paste it into the address parameter of the wget command.


The wget is very stable and has a strong adaptability in the case of very narrow bandwidth and unstable networks. If the download fails because of the network, wget will keep trying until the entire file is downloaded. If the server interrupts the download process, it will again be linked to the server to continue downloading from where it stopped. This is useful for downloading large files from servers that have limited link times. It's a bug-like existence.


Continuation of interrupted downloads


To continue an interrupted download, simply add the-c parameter to the same download command, for example:


Wget-c Http://cdimage.debian.org/debian-cd/8.2.0/i386/iso-cd/debian-8.2.0-i386-netinst.iso


C is an abbreviation for English continue, which means "continue".


Wget has a lot of parameter options that we can't enumerate. Refer to the wget manual: Man wget


A nice place for wget is that it shows the progress of the download. The FTP command We will learn later will not show the download progress.


SCP: Inter-network copy


We learned the CP command in our previous course, which is used to copy files on your own computer.


The SCP is the abbreviation for secure copy, which means "secure copy." This command allows us to copy files from one computer to another over the network. Of course, the copied information is safe, as its name implies.


There is also a command rcp, which is the abbreviation for remote copy. You can do the same thing, but the information is not secured and is not recommended.


The SCP is a bit like the ssh (Secure SHell) you learned in the previous lesson. This is not a coincidence, because the SCP works based on the principle of SSH. SSH first creates a pipeline of secure communications between two computers connected over the network (as shown in the previous lesson), and the SCP uses this pipeline to securely copy files.


The basic command format for SCP is as follows:


SCP Original_file Destination_file


Where original_file represents the source file, which is the file being copied. Destination_file represents the target file, which is the copy-generated file.


These two files can be represented in the following ways:


[Email Protected]:file_name


Where user is the login name, IP is the domain name (for example, google.fr) or IP address (for example, 89.231.45.67), file_name is the file path. Do not forget the middle of the @ sign and the colon (:).


Copy files from your own computer to another computer


This is simple, for example:


SCP image.png [Email protected]:/home/oscar/images/


It means to copy the Image.png file under the current folder in My computer to the/home/oscar/images directory of the remote computer (the IP address is 89.231.45.67), and the file name will not change (or image.png, you can change the name). As shown in the following:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymaqnuioqmzu7vdrwl8xn3uiblshlmiax8ewzvazir9bcqq4tzqg4x1vbogb3zlsxasg9m2jg4umk7g/0?wx_fmt=jpeg "alt=" 0?wx_fmt=jpeg "/>


Of course, the SCP will ask you to enter the password of the user Oscar for the remote computer (IP address is 89.231.45.67). Enter the password, press ENTER, and the copy is started.


Copy files from Another computer to your computer


A similar use, for example:


SCP [Email protected]:/home/oscar/images/image.png file_changed_name.png


Represents a copy of image.png from the/home/oscar/images directory of the user Oscar of the remote computer (IP address is 89.231.45.67) to the current folder in My computer and renamed to File_changed_ Name.png (not renamed can also). As shown in the following:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymaqnuioqmzu7vdrwl8xn3u9vbwnrshic0oam0icqowev6u4fom9tslerfliaqmbpc17q4icovkxkf9gw/0?wx_fmt=jpeg "alt = "0?wx_fmt=jpeg"/>

Modify Port


In the above command, we do not specify which port to use, only the IP address is specified. The default port number is 22, which is the same as SSH. We can also modify the port number with the-p parameter. For example:


Scp-p 7821 [email protected]:/home/oscar/images/image.png.


Represents a copy of image.png from a remote computer (IP address is 89.231.45.67, Port 7821) of the user Oscar's/home/oscar/images directory under the current folder in My Computer, the name does not change. Here, a dot (.) is used to indicate the current directory.


Note: In the previous lesson, SSH modified the port number using the-p parameter, and p is lowercase. The SCP modifies the port number using the-p parameter, and p is uppercase.


Ftp&sftp: Transferring files


FTP is the abbreviation for File Transfer protocol, which represents the document transfer Protocol. As the name implies, it is used to transfer files.


FTP protocol has been a little old, born in 1985, than the small part of the age. It is still the most common protocol for transferring files. is the so-called "Lianpo old, still can rice no", others are "ftp, blades not old."


There are two main scenarios of using ftp:


    1. Download files from the public FTP server. In general, when you click on the download link on your browser, the browser will do so in an automatic and transparent manner. In this case, the connection is anonymous.

    2. Upload or download files from a private FTP server. When we rent a server from a server tenant as a personal website, the lessor usually gives us an FTP login name and password, which we can connect to upload and download files. In this case, the connection is required for authentication.


Since not every reader has its own private FTP server, we will connect to the public FTP server when we demonstrate below. Of course, if you want to connect to a private FTP server, the method is the same.


We use the pure command line in the form of operation, of course, there are also many excellent FTP software, can provide graphical interface, such as the famous FileZilla.


Connect to an FTP server


We tried to connect to the Debian FTP server at the following address: ftp://ftp.debian.org


The method is simple:


FTP ftp.debian.org


The Debian FTP server should respond and ask you to enter a user name and password. For public FTP servers, the user name is generally populated with anonymous ("anonymous").


The password you enter whatever you want will be accepted.


After the login is successful, you will see a message similar to the following:


Successful Login.

Remote system type is UNIX.

Using binary mode to transfer files.

Ftp>


Now you have the command prompt, that's the ftp>.


You can then enter the FTP command.


Operating in the FTP server


Good news: The commands you can use on the FTP server are basically the same as the Linux commands we've learned so far.


For example:


LS: List the files of the current directory

PWD: Displays the path to the current directory

CD: Convert directory


You can try other commands.


File transfer


If you want to upload and download a file, there are two commands to know:


    • Put: For uploading files

    • Get: For downloading files


As shown in the following:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymaqnuioqmzu7vdrwl8xn3u20ahl4ewooodgdlqds9xiaxrd0hvbyyjrnyy9w7vvvzrhgzre6g0hqq/0?wx_fmt=jpeg "alt=" 0 ? wx_fmt=jpeg "/>


Let's download a file to try it (README):


Ftp> Get README

Local:readme Remote:readme

PORT command successful. Consider using PASV.

Opening BINARY mode data connection for README (940 bytes).

226 File send OK.

940 Bytes Received in 0.00 secs (918.9 kb/s)


After the download, the Readme file is now in your current directory.


What if you connect to an FTP server and want to run commands on your own computer?


Just add an exclamation point to the command, for example:


!pwd


Will execute the PWD command on your computer instead of on the FTP server.


Other FTP commands


There are a number of other FTP commands that we don't enumerate.


Use man FTP to see the other available commands. You will find that not all of the commands are the same as the Linux commands you have learned so far. For example, deleting a file does not use the RM command, but the delete command.


To disconnect from the FTP server, you can use the Ctrl+d key combination. You can also use the Bye,exit or quit command, the effect is the same.


SFTP: Secure Encrypted FTP


The FTP command, while convenient, has one fatal disadvantage: insecure, data is not encrypted. Anyone, if connected to the same network, can find a way to intercept the data you transmit, or your password.


Therefore, we need to take out sftp. SFTP is the abbreviation for secure FTP. Represents "Secure FTP".


SFTP is also based on SSH, so login requires username and password, use the following:


SFTP [email protected]


For example:


SFTP [email protected]


Once you have entered the username and password, the other actions are the same as FTP after the connection. Only the communication is encrypted and more secure.


Use the man sftp to see the other available commands and parameters.


In the above command, we do not specify which port to use, only the IP address is specified. The default port number is 22, which is the same as SSH. We can also modify the port number with the-oport parameter. For example:


Sftp-oport 3592 [email protected]


Rsync: Synchronous Backup


The rsync command is easy to use and powerful.


Rsync is a small program that needs to be installed, and the default system generally does not have this command.


sudo apt-get install rsync


The Rsync command allows us to synchronize two directories, regardless of whether the two directories are on the same computer or different computers (with a network connection).


Rsync should be the most commonly used "incremental backup" command. What is an "incremental backup"?


Incremental backups (incremental backup) are a type of backup, meaning that after a full or last incremental backup, each subsequent backup only needs to back up the files that were added or modified compared to the previous one.


What are the benefits of backup?


Imagine if you didn't take the paper. So once your personal computer encounters an accident, such as bad, stolen, etc. Then your data will not come back. If there is a dozens of-page paper in it, it is possible to cry down the Great Wall. Many friends have had such a bitter experience.


It's a good habit to back up before, and I'll back up more than just one place.


So backup is important. If you back up the files on your computer to a remote server, as shown in:



650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymaqnuioqmzu7vdrwl8xn3umulegy25ibrufiblhic8ibz4mtwgibxhgiaiag97pcgpsloudiapf7zlqhfbsg/0?wx_fmt=jpeg "alt=" 0?wx_fmt=jpeg "/>


It is very convenient to use rsync for backup. If you have your user home directory back to the server, maybe there are more than 10 g content ah.


The first time you back up, you need to transfer the entire more than 10 g content, but later, only need to transfer the new or modified content is enough, do not need to pass again. This is the strength of rsync, the benefits of the so-called "incremental backup".


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymmiabhbljicyxu1fbjqoiad7gxfmrtwcuwwd9fcjpbtf7xamxndgatp8s9iczg6iaich82qczmjmdt8icmg/0?wx_fmt=jpeg " alt= "0?wx_fmt=jpeg"/>

As shown, I only transferred the new file with Rsync. The others are no longer transmitted.


Rsync is like the more intelligent SCP.


Back up to a different directory on the same computer


Rsync-arv images/backups/


The above command to back up all files under the images directory to the backups directory.



The-arv parameters indicate:


    • -A: Retains all information about the file, including permissions, modification dates, and so on.

    • -R: Recursive invocation. All files that represent subdirectories are also included.

    • -V: Redundant mode. Output detailed operation information.


deleting files


By default, rsync does not delete files from the destination directory while synchronizing. For example, you delete a file from your source directory (the synchronized directory), but when you synchronize with rsync, it does not delete the same files in the synchronized directory.


If you want Rsync to also synchronize the delete operation. Then you can do this:


Rsync-arv--delete images/backups/


Add the--delete parameter to it.


Back up to another computer's directory


Rsync-arv--delete images/[email protected]:backups/


Isn't it simple?


For more parameters, you can learn with man rsync.


Of course, the power of rsync never ends here.


You can configure rsync yourself so that it is backed up to a directory of the specified IP address from the specified directory (which can be multiple directories), and you can specify which types of files are to be backed up, which types do not back up, and then use this long list of commands uniformly to write a file (for example, named Backup) in a shell. Make it executable (with the chmod command), and then add the path of the file to path.


This way you will be in the future regardless of the directory input Backup,rsync to help you automatically sync, very handsome. This acid is cool, self-evident ~


As for how to do, even if it is left to everyone's after-school interest homework. Can own Baidu, such as "Ubuntu under Rsync configuration."


Summarize


    1. The wget command can download the file.

    2. In order to copy files from one computer to another, we can use the SCP command. It uses the SSH mentioned in the previous lesson, so the transmission is encrypted and is secure.

    3. We can use the FTP command to connect to an FTP server, then we can upload and download files.

    4. SFTP and FTP commands are similar, but it uses SSH, so the transmitted information is encrypted.

    5. The rsync command synchronizes the contents of two files (clips) on the same computer or on two different computers, and it is particularly convenient to use the rsync command to back up files.


part fourth, lesson four, notice


Today's class will come here, together refueling it!

Next lesson we study: analyzing the network, isolating the fire

This article is from the "Programmer Alliance Frogoscar" blog, so be sure to keep this source http://4526621.blog.51cto.com/4516621/1730082

"Linux Discovery Tour" Part IV lesson Three: file transfer, dashing sync

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.