Linux File Transfer (1)

Source: Internet
Author: User
Tags ftp site scp command secure copy
The common format of the ftpftp command is as follows: $ ftp host name/IP. the host name/IP address is the host name or IP address of the remote machine to be connected. In the command line, the host name is optional. if the host name is specified, ftp attempts to connect to the ftp service program of the remote machine. if the master... ftp is not specified

The ftp command format is as follows:

$ Ftp host name/IP address

The "host name/IP address" is the host name or IP address of the remote machine to be connected. In the command line, the host name is optional. if the host name is specified, ftp attempts to connect to the ftp service program of the remote machine. if the host name is not specified, ftp will give a prompt, wait for the user to enter the command.

At this time, enter the open sub-command plus the host name or IP address after the ftp> prompt, and try to connect to the specified host. No matter which method is used, if the connection is successful, you need to log on to the remote machine. If you have an account on a remote machine, you can use this account through ftp and provide a password. The read and write permissions of the user account on the remote machine determine the files that the user can download and the directories in which the uploaded files are stored. After successfully logging on to the remote site, you can freely use the sub-commands provided by ftp at the "ftp>" prompt. The most common sub-commands are shown in the following table.

Table 1. ftpSub-commands

 

Command

Description

Ls

List the current directory of the remote machine

Cd

Change the working directory on a remote machine

LCD

Change the working directory on the local machine

Ascii

Set the file transmission mode to ASCII

Binary

Set file transfer mode to binary mode

Close

Terminate the current ftp session

Get (mget)

Transfers a specified file from a remote machine to a local machine

Put (mput)

Transfers a specified file from a local machine to a remote machine

Open

Connect to a remote ftp site

Quit

Disconnect from a remote machine and exit ftp

?

Display local help information

!

Go to Shell

Prompt 1

Disable interaction mode

 Instance used:

You can use ftp scripts to automatically complete file transfer tasks. The specific method is to use the-in option of the ftp command and redirect the input of the ftp command. Now we will compile a remote server login using ftp and download file1.log and file2.sh to the local machine/opt/ibm/in the/home directory in the bin file format /, upload the file file3.jave from the local/opt directory to the remote server/home.

 

Ftp-ni <+

Open $ IP

User $ USERNAME $ PASSWD

Bin

Cd/home

LCD/opt/ibm

Mget file1.log file2.sh

LCD/opt

Mput file3.jave

Ls

Bye

Rcp

Rcp indicates "remote file copy" (remote file copy ). This command is used to copy files between computers. There are two formats. The first format is used to copy files to files. The second format is used to copy files or directories to another directory.

Basic syntax:

Rcp [-px] [-k realm] file1 file2

Rcp [-px] [-r] [-k realm] file directory

Each file or directory parameter can be either a remote file name or a local file name. The remote file name can be in the following format: rname @ rhost: path. rname indicates the remote user name, rhost indicates the remote computer name, and path indicates the path of the file. The following table describes the meanings of parameters of the rcp command.

 

Option

Description

-R

Recursively copy all content in the source directory to the target directory. If this option is used, the target must be a directory.

-P

Tries to keep the modification time and mode of the source file and ignore umask.

-K

Request rcp to obtain the Kerberos permission for the remote host in the specified region, instead of obtaining the Kerberos permission for the remote host in the remote host region determined by krb_relmofhost (3.

-X

Performs DES encryption for all transmitted data. This affects response time and CPU utilization, but improves security.

If the path specified in the file name is not the complete path name, the path is interpreted as the home directory of the user with the same name on the remote machine. If no remote user name is provided, the current user name is used. If the path on the remote machine contains special shell characters, you need to use the backslash (\), double quotation marks ("), or single quotation marks (') to enclose it, allow remote interpretation of all shell metacharacters. It must be noted that the rcp does not prompt for a password. it uses the rsh (remote shell) command to execute the copy operation.

Use instance:

Copy local files to the remote logon Directory

Rcp

Copy multiple local files to the subdirectory of the remote logon Directory

Rcp

Copy multiple files from multiple remote sources to remote targets with different user names

Rcp

Scp

The scp command copies files between hosts on the network. it is short for secure copy. Scp commands use ssh to transmit data and use the same authentication mode as ssh to provide the same security. The usage of the scp command is very similar to that of the rcp command. Scp is generally recommended because it is safer than rcp.

We can configure ssh so that you do not need to enter the user name and password each time when copying files between two machines.

Basic syntax

Scp [-1246 BCpqrv] [-c cipher] [-F ssh_config] [-I identity_file]

[-L limit] [-o ssh_option] [-P port] [-S program]

[[User @] host1:] file1 [...] [[user @] host2:] file2

To use the scp command, you need to enter the password. if you do not want to enter the password every time, refer to the following method.

First generate the key pair

$ Ssh-keygen-t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/user/. ssh/id_rsa ):

Created directory '/home/user/. ssh '.

Enter passphrase (empty for no passphrase ):

Enter same passphrase again:

Your identification has been saved in/home/user/. ssh/id_rsa.

Your public key has been saved in/home/user/. ssh/id_rsa.pub.

The key fingerprint is:

10: 66: da: 38: 85: 8a: 8c: bd: db: 9c: 6e: eb: ee: bd: 7d: 15 user @ somehost

Here, we specify to generate an rsa key. When you are prompted about the key storage path and password, you can press enter to use the default path and empty password. In this way, the generated public key is saved in $ HOME/. ssh/id_rsa.pub, and the private key is saved in $ HOME/. ssh/id_rsa. Copy the contents of the public key in this key pair to the $ HOME/. ssh/authorized_keys file on the machine to be accessed. In this way, you do not need to enter the password when accessing the machine again.

Instance used:

Copy the local file/etc/eva. log to the home directory of the remote machine sysB and user.

Scp/etc/eva. log user @ sysB:/home/user

Copy the file/home/uesr/eva. log on the remote machine sysB to The Local/etc directory and keep the file attributes unchanged.

Scp-p user @ sysB:/home/uesr/eva. log/etc

Copy the directory/home/user on sysB to local/home/user/tmp,

Scp-r user @ sysB:/home/user/tmp

Wget

Wget is a GPL-authorized free software package that automatically obtains files from the network. It is a non-interactive command line tool. Supports HTTP, HTTPS, and FTP protocols, proxy servers, and resumable data transfer. Wget supports recursive download, which allows you to track links on the HTML page and download them in turn to create local versions of remote servers, completely reconstruct the directory structure of the original site, and implement remote website images. During recursive download, wget converts the hyperlink on the page to point to a local file to facilitate offline browsing. Due to non-interactive features, wget supports running in the background. you can continue running after exiting the system. Powerful functions, easy to set.

Basic syntax

Wget [options] [URL-list]

Wget has many different parameters for obtaining remote site information, common parameters are as follows, more parameters please refer to wget help manual http://www.gnu.org/software/wget/manual/wget.html

Table 3. common parameters of wget

 

Option

Description

-R

Recursively downloads all directories and files on the server. The-l option is used to specify the recursive depth.

-B

Background Download

-M

Create site images

-C

Specifies the resumable Upload function. This feature requires the server to support resumable data transfer.

-I

Specifies the download directory list for batch download.

-A/-R

Specifies the list of accepted/rejected downloads for selective download.

-- Proxy = on/off

Whether to use the proxy server for download

-T, -- tries = NUMBER

Maximum number of attempts (0 indicates no limit, 20 by default)

-Nc, -- no-clobber

Do not overwrite existing files

-N, -- timestamping

Only download new files than local files

-Nd -- no-directories

No directory structure is created

-X, -- force-directories

Force create directory structure

-NH, -- no-host-directories

Does not inherit the host directory structure

-P, -- directory-prefix = PREFIX

Set directory prefix

Instance used:

Recursively downloads information for http://www.ibm.com.cn sites. Download all files and fragments required to display the complete web page. No upper-level directory search is performed during download and the absolute link is converted to the relative link.

Http://www.ibm.com.cn of wget-r-p-np-k

An image that creates a http://www.ibm.com.cn on a local hard disk is saved to the subdirectory www.ibm.com.cn next to the current directory (you can also use the-nH parameter to specify that this subdirectory is not created, directly create the image directory structure in the current directory. the recursive depth is 4 and the number of retries is infinite. (if the connection fails, wget will try again forever until the task is completed)

Http://www.ibm.com.c wget-m-l4-t0

Use a proxy for download and resumable Upload. The PROXY can be set in the environment variable PROXY or wgetrc file. -The c option requires that the service support resumable data transfer.

Http://www.ibm.com.cn wget-Y on-c

Author "devilkin"

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.