"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


Content Brief Introduction

1 Part IV lesson three: file transfer. Dashing synchronization

2, the Fourth part of the lesson four: analysis of the network . Isolated fire Protection


file transfer. Chic Sync


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


After the study of the previous lesson. We already know how to connect to other computers remotely.

From now onwards. You will be able to execute commands on your computer to control the distance and a computer, very cool.


We continue to explore the fantasy web world of Linux.

This network world is more special, perhaps you already have some experience: predecessors have done a lot of efforts, rely on encryption method to ensure the security of data transmission between the network. In case our personal information leaks. Like password.


In this lesson we will learn about file transfer. Mainly divided into the following aspects:


    • How to download files

    • How to connect to FTP, read, download files

    • How to copy files securely


The knowledge of the Web, which is covered in this article, can be consulted on 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. is: wget


It allows us to download files directly from the terminal console, simply by giving the HTTP or FTP address of the file.


Command format:


wget [references] [URL address]


Like what:


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


It 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, you just need to press CTRL +C


Can see a progress bar appears below, showing the download progress:




38% indicates that 38 has been downloaded.

117K/S is the download speed. Represents 117kb per second.

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


So. How do I get an address for wget download in advance?


You can use the browser (for example, Firefox) to find the file you want to download. Then click the right mouse button on the file. Left click "Copy link Address", for example:




You can then paste it into the address number of the wget command.


The wget is very stable and has very strong adaptability in the case of very narrow bandwidth and unstable networks. Assume that the download failed because of network reasons. Wget will keep trying until the entire file is finished downloading. Assuming that 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 with an interrupted download, simply add the-c parameter to the same download command. Like what:


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


c is the abbreviation of English continue. Indicates "continue".



Wget has a number of options, which we cannot enumerate. Be able to see 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 used to learn the CP command in our course, which is for copying 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 sees.


There is also a command rcp, which is the abbreviation for remote copy. Can do the same thing. But the information is not secure, not recommended.


The SCP is a bit like the ssh (Secure SHell) you learned in the previous lesson.

This is not a coincidence, since 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 seen in the previous lesson), and the SCP uses this pipeline to securely copy files.


The basic command format for the SCP is as follows:


SCP Original_file Destination_file


The original_file represents the source file. Is the file being copied.

Destination_file represents the target file, which is the copy-generated file.


These two files can be represented as follows:


[Email Protected]:file_name


User is the login name. IP is a domain name (such as google.fr) or an IP address (such as 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 a computer


This is very easy, for example:


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


Copy the Image.png file under the current folder in My computer to the/home/oscar/images folder of the remote computer (the IP address is 89.231.45.67) of the user Oscar. The file name does not change (or image.png, you can change the name).

For example, as seen in:


Wx_fmt=jpeg ">


Of course. The SCP will ask you to enter the password of the user Oscar for the remote PC (IP address is 89.231.45.67). Enter password, carriage return. The copy is started.


Copy files from one computer to your computer


Similar methods of use, such as:


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


The/home/oscar/images folder that represents the user Oscar from the remote computer (IP address is 89.231.45.67) is copied under the current folder in My computer and renamed to File_changed_. Image.png Name.png (not renamed also can).

For example, as seen in:


Wx_fmt=jpeg ">

Change 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 change the port number. Use the-p parameter. Like what:


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


Indicates that the name does not change under the/home/oscar/images folder of the user Oscar of the remote computer (IP address is 89.231.45.67,port7821), under the current folder in My computer. The current folder is represented here with a dot (.).


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


Ftp&sftp: Transferring files


FTP is the abbreviation for file Transfer protocol. Represents the file Transfer protocol. Name implies. is used to transfer files.


The FTP protocol is already a bit old, born in 1985. It's older than a small weave. It is still the most frequently used 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 the file from the public ftpserver. Generally, when you click on the download link on your browser, the browser completes the operation in its own active and transparent manner.

      Such a case. The connection is anonymous.

    2. Upload or download files from a private ftpserver. When we rent a server from the server lessor as a personal site, the lessor usually gives us an FTP login name and password, 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 ftpserver, so the following demo. We will connect to the public ftpserver. Of course, assuming you want to connect to a private Ftpserver, the method is the same.


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


Connect to Ftpserver


We tried to connect to Debian's ftpserver. Address such as the following: ftp://ftp.debian.org


The method is very easy:


FTP ftp.debian.org


Debian's ftpserver should respond and ask you to enter username and password. For public ftpserver,username generally fill in anonymous ("anonymous").


Password whatever you enter 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 a command prompt, that's the ftp>.


You will be able to enter the FTP command.


Working in Ftpserver


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


Like what:


LS: Lists the files for the current folder

PWD: Displays the path of the current folder

CD: Convert folder


You can try other commands.


File transfer


Suppose you want to upload and download files. There are two commands to be aware of:


    • Put: For uploading files

    • Get: For downloading files


For example, as seen in:



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)


Complete the download. The Readme file is now in your current folder.


Suppose you connect to a ftpserver, but want to execute commands on your own computer. What do we do?


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


!pwd


You run the PWD command on your computer instead of running on Ftpserver.


Other FTP commands


There are a number of other FTP commands. We will not enumerate them.


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 at the moment.

Like what. Deleting a file does not use the RM command, but the delete command.


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



SFTP: Secure Encrypted FTP


Although convenient, the FTP command has a fatal disadvantage: unsafe. The data is not transmitted encrypted. No matter who you are, just connect 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 ssh-based. So login needs username and password. Use methods such as the following:


SFTP [email protected]


Like what:


SFTP [email protected]


Once you have entered username and password, connect on the post. The other operation is the same as FTP. It's just that the communication is encrypted and more secure.


Use the man sftp to see the other available commands and the number of references.


The above command. We did 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 change the port number. Use-oport for the number of references. Like what:


Sftp-oport 3592 [email protected]


Rsync: Synchronous Backup


The rsync command is easy to use and very powerful.


Rsync is a small program. Need to install, the default system generally does not have this command.


sudo apt-get install rsync


The Rsync command allows us to synchronize two folders. Whether the two folders are on the same computer or a different computer (with a network connection).


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


Incremental backups (incremental backup) are a type of backup that is after a full backup or a previous incremental backup. Each subsequent backup only needs to back up the files that were added or changed compared to the previous one.


What are the advantages of backup?


Imagine if you didn't take the paper. So once your PC is out of measure, like it's broken, stolen, and so on. Then your data will not come back. Suppose there is a dozens of-page paper in it, it is possible to cry down the Great Wall. Many friends have had such dire pain experience.


Small series has been a good habit of backup. And I'm backing up more than just going in one place.


So backup is very important. If you back up the files on your computer to a remote server, for example, see:




Use rsync to make backups. is very convenient.

If. You back up your user home folder to the server, perhaps more than 10 g of content ah.


The first backup, you need to transfer the full more than 10 g content, but later, just need to transfer the new or changed content is enough, do not need to pass again. This is the strength of rsync, the advantages of the so-called "incremental backup".




As you can see, I just transferred the new file with Rsync. The others were not transmitted.


Rsync is like the more intelligent SCP.



Back up to another folder on the same computer


Rsync-arv images/backups/


The above command, back up all files under the images folder to the Backups folder.



The-arv parameters indicate:


    • -A: Retains all information about the file. Include permissions, date changes, and so on.

    • -R: Recursive invocation.

      All the files that represent subfolders are also included.

    • -V: Redundant mode.

      Output specific operation information.


deleting files


By default, rsync does not delete files from the destination folder while synchronizing.

For example, you delete a file from your source folder (the synced folder). But when synchronizing with Rsync. It does not delete the same files in the synchronization folder.


Suppose you want rsync to also synchronize the delete operation.

So you can do this:


Rsync-arv--delete images/backups/


Add--delete to the number of references.



Back up to a folder that also has a computer


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


Isn't it very easy.


As with many other parameters, you can learn with man rsync.


Of course, the power of rsync never ends here.


You can configure rsync yourself. Causes it to be backed up from the specified folder (which can be multiple folders) to a folder of the specified IP address, and to specify which types of files are to be backed up, and which types do not back up. This long list of commands is then unified with the shell to write a file (for example, called backup), so that it can be run (with the chmod command), and then the path of the file is added to the path.


This way you will enter backup in whichever folder you choose. Rsync will help you to actively 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. Able to own Baidu, such as "under the Ubuntu rsync configuration."



Summarize


    1. The wget command is capable of downloading files.

    2. In order to copy files from one computer to another computer. We are able to 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 a ftpserver, and 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 is here. Let's refuel!

Next lesson we study: analyzing the network. Isolated fire Protection

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

Related Article

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.