File transfer of Linux command

scp

The file is copied between the local host and the remote host by encryption

Supplementary notes

scp command is used to remotely copy files under Linux. cp is a similar command, but cp is only copied locally, not across servers, and scp transmission is encrypted. It may affect the speed slightly. When your server hard disk becomes read-only read only system, scp can help you move the files out. In addition, scp does not occupy much resources and will not increase the system load. At this point, rsync is far less than it. Although rsync is a little faster than scp, when there are many small files, rsync will lead to very high I/O of the hard disk, and scp basically does not affect the normal use of the system.

grammar

scp(option)(parameter)

option

-1: use ssh Protocol version 1;
-2: use ssh Protocol version 2;
-4: use ipv4;
-6: use ipv6;
-B: Run in batch mode;
-C: Use compression;
-F: appoint ssh Configuration file;
-i: identity_file Read the key file used in the transfer from the specified file (e.g. Amazon cloud) pem),This parameter is passed directly to ssh;
-l: Specify broadband restrictions;
-o: Specify the used ssh Options;
-P: Specify the port number of the remote host;
-p: Retain the last modification time, last access time and permission mode of the file;
-q: Copy progress is not displayed;
-r: Copy recursively.

parameter

  • Source file: Specifies the source file to copy.
  • Target file: target file. Format is user@host : filename (the file name is the name of the target file).

example

The scp command copied from remote to local is the same as the above command. Just exchange the last two parameters of the command copied from local to remote in order.

Copy files from remote machine to local directory

scp root@10.10.10.10:/opt/soft/nginx.tar.gz /opt/soft/

Download nginx -. From the directory of / opt/soft / on the 10.10.10.10 machine tar. GZ file to the local / opt/soft / directory.

Copy OpenVPN from Amazon cloud to local directory

scp -i amazon.pem ubuntu@10.10.10.10:/usr/local/openvpn_as/etc/exe/openvpn-connect-2.1.3.110.dmg openvpn-connect-2.1.3.110.dmg

Download the openvpn installation file from the 10.10.10.10 machine to the current local directory.

Copy from remote machine to local machine

scp -r root@10.10.10.10:/opt/soft/mongodb /opt/soft/

Download the mongodb directory from / opt/soft / on the 10.10.10.10 machine to the local / opt/soft / directory.

Upload local files to the specified directory of the remote machine

scp /opt/soft/nginx-0.5.38.tar.gz root@10.10.10.10:/opt/soft/scptest
# Specify port 2222
scp -rp -P 2222 /opt/soft/nginx-0.5.38.tar.gz root@10.10.10.10:/opt/soft/scptest

Copy the file nginx-0.5.38 in the local / opt/soft / directory tar. GZ to the opt/soft/scptest directory of the remote machine 10.10.10.10.

Upload the local directory to the specified directory of the remote machine

scp -r /opt/soft/mongodb root@10.10.10.10:/opt/soft/scptest

Upload the local directory / opt/soft/mongodb to the directory of / opt/soft/scptest on the remote machine 10.10.10.10.

ftp

Used to set file system related functions

Supplementary notes

ftp command is used to set file system related functions. ftp server is common on the Internet. The function of Linux ftp command is to control the transfer of files between local machine and remote machine by command. Here, some frequently used commands of Linux ftp command are introduced in detail. I believe it will be very easy to master these commands for ftp operation with Linux.

grammar

ftp(option)(parameter)

option

-d: Display the instruction execution process in detail to facilitate troubleshooting or analyze the execution of the program;
-i: Turn off interactive mode without asking any questions;
-g: Turn off the extension feature of local host file name supporting special characters;
-n: Do not use automatic login;
-v: Displays the instruction execution process.

parameter

Host: Specifies the host name or ip address of the FTP server to which you want to connect.

example

ftp> ascii  # Set file transfer in ASCII mode (default) 
ftp> bell   # Every time the file transfer is completed, the alarm will be prompted 
ftp> binary # Set to transfer files in binary mode 
ftp> bye    # Terminate the host FTP process and exit the FTP management mode 
ftp> case   # When ON, use MGET command to copy the file name to the local machine and convert it into lowercase letters 
ftp> cd     # Same as UNIX CD command 
ftp> cdup   # Return to the previous directory 
ftp> chmod  # Change the file permissions of the remote host 
ftp> close  # Terminate the remote FTP process, return to the FTP command state, and all macro definitions are deleted 
ftp> delete # Delete files from remote hosts 
ftp> dir [remote-directory] [local-file] # Lists the files in the current remote host directory If there is a local file, write the result to the local file 
ftp> get [remote-file] [local-file] # Transfer from remote host to local host 
ftp> help [command] # Interpretation of the output command 
ftp> lcd # Change the working directory of the current local host. If default, go to the HOME directory of the current user 
ftp> ls [remote-directory] [local-file] # Same as DIR 
ftp> macdef                 # Define macro commands 
ftp> mdelete [remote-files] # Delete a batch of files 
ftp> mget [remote-files]    # Receive a batch of files from the remote host to the local host 
ftp> mkdir directory-name   # Create a directory in the remote host 
ftp> mput local-files # Transfer a batch of files from the local host to the remote host 
ftp> open host [port] # Re - establish a new connection 
ftp> prompt           # Interactive prompt mode 
ftp> put local-file [remote-file] # Transfer a local file to the remote host 
ftp> pwd  # Lists the current remote host directory 
ftp> quit # Same as BYE 
ftp> recv remote-file [local-file] # Same as GET 
ftp> rename [from] [to]     # Change the file name in the remote host 
ftp> rmdir directory-name   # Delete the directory in the remote host 
ftp> send local-file [remote-file] # Same as PUT 
ftp> status   # Displays the current FTP status 
ftp> system   # Displays the remote host system type 
ftp> user user-name [password] [account] # Log in to the remote host again with a different user name 
ftp> ? [command] # Same as help [command] specify the name of the command that needs help. If no command is specified, ftp will display a list of all commands.
ftp> ! # Exit from ftp subsystem to shell.

FTP anonymous login account password

account number: anonymous
 password: anonymous@

Close FTP connection

bye
exit
quit

Download File

ftp> get readme.txt # Download readme Txt file
ftp> mget *.txt     # download 

Upload file

ftp> put /path/readme.txt # Upload readme Txt file
ftp> mput *.txt           # Multiple files can be uploaded

ftpcount

Displays the number of users currently logged in via FTP

Supplementary notes

Displays the number of users who have FTP logged in. Execute this command to know the current number of people logging in the system with FTP and the upper limit of FTP login.

Syntax:

ftpcount

ftpshut

Shut down the FTP server at the specified time

Supplementary notes

Function Description: close the FTP server at the specified time. This instruction provides the system manager to shut down the FTP server at the set time, and can send a warning message to notify the user before shutting down. If the shutdown time is set to "none", the server will be shut down immediately. If it is set with "+ 30", it means that the server will shut down after 30 minutes. And so on. If the format of "1130" is used, it means that the server will shut down at 11:30 every day, and the time format is 24-hour system. After the FTP server is shut down, a file named shutmsg will be generated in the / etc directory. After deleting it, the function of the FTP server can be started again.

Syntax:

ftpshut [-d<minute>][-l<minute>][Closing time]["Warning message"]

Parameters:

-d<minute>   Cut off all FTP Connection time.
-l<minute>   Stop accepting FTP Time of login.

ftpwho

Displays the information of each current ftp session

Supplementary notes

The ftp who command is the working instruction of the ftp server suite proftpd, which is used to display the information of each current ftp session.

grammar

ftpwho(option)

option

-h: Display help information;
-v: Detailed mode, output more information.

ncftp

Is an enhanced FTP tool

Supplementary notes

ncftp command is an enhanced FTP tool, which is more powerful than the traditional FTP command. FTP allows users to download files stored on the server host and upload files to the remote host for placement. ncftp is the leader of text mode FTP program. It has various characteristics, including displaying transmission rate, download progress, automatic renewal, bookmarking, firewall and proxy server.

grammar

ncftp(option)(parameter)

option

-u: Specify login FTP The user name used when the server;
-p: Specify login FTP The password used in the server;
-P: If FTP The server is not using the default TCP Port 21 of the protocol, use this option to specify FTP The port number of the server.
-m: Try to create a directory in the directory location before transferring(Used for directory transfer)
-R: Transmittal subdirectory

parameter

FTP server: specify the ip address or host name of the remote FTP server.

install

wget ftp://ftp.ncftp.com/ncftp/ncftp-3.2.3-src.tar.gz
tar zxvf ncftp-3.2.3-src.tar.gz
cd ncftp-3.2.3/
./configure --prefix=/usr/local/ncftp
make && make install

example

Upload all files and directories in the local / etc / directory to the flv/games / directory of the FTP server (if there is no flv/games / directory, it will be created automatically).

/usr/local/ncftp/bin/ncftpput -u koumm -p koumm -P 21 -m -R 192.168.162.137  flv/games/ /etc/*

Instruction description

The basic command of ncftp is the same as that of ordinary ftp. You can enter help to get the command list. For all commands, detailed help can be obtained in the format of help < command >. l starts with the command to execute locally, and others are the operation commands to log in to the ftp service directory.

Operation command of added local file system:

  • lls: list the current local directory files;
  • lmkdir: establish local directory;
  • lrename: rename the local file;
  • lpwd: displays the current local path;
  • lchmod: change local file permissions;
  • lpage: display local file content;
  • lrm: delete local files;
  • lrmdir: delete local directory.

tftp

Use the TFTP protocol to transfer files between the native computer and the TFTP server

Supplementary notes

The TFTP command is used to transfer files between the local machine and the TFTP server using the TFTP protocol.

TFTP is the simplest network protocol used to download remote files. It is implemented based on UDP protocol. The TFTP development environment of embedded linux includes two aspects: one is the TFTP server support of linux server, and the other is the TFTP client support of embedded target system. Because u-boot supports TFTP client built-in, the embedded target system does not need to be configured. The following describes the configuration of TFTP server on linux server in detail.

grammar

tftp(option)(parameter)

option

-c: Designation and tftp Instructions to be executed immediately after the server connection is successful;
-m: Specifies the file transfer mode. Can be ASCII perhaps Binary;
-v: Display the detailed execution process of instructions;
-V: Displays instruction version information.

parameter

Host: Specifies the ip address or host name of the tftp server where tftp will be online.

example

1. Install tftp server

xinetd, tftp and tftp server software need to be installed

If you can access the Internet, install via yum:

yum install xinetd
yum install tftp
yum install tftp-server

If you cannot access the Internet, you can directly install the rpm package provided:

rpm -ivh xinetd-2.3.14-18.fc9.i386.rpm
rpm -ivh tftp-0.48-3.fc9.i386.rpm
rpm -ivh tftp-server-0.48-3.fc9.i386.rpm

2. Configure tftp server

Modify / etc / xinetd D / TFTP file, change disable=yes to disable=no. It is mainly used to set the root directory of TFTP server and start the service. The revised document is as follows:

service tftp
{
       socket_type           =dgram
       protocol              =udp
       wait                  =yes
       user                  =root
       server                =/usr/sbin/in.tftpd
       server_args           =-s  /home/mike/tftpboot -c
       disable               =no
       per_source            =11
       cps                   =100 2
       flags                 =IPv4
}

Description: modify item server_ Args = - s < Path > - C, where The location can be changed to the root directory of your TFTP server. The parameter - s specifies chroot and - c specifies that files can be created.

3. Start the tftp server and turn off the firewall

/etc/init.d/iptables stop        # Turn off the firewall
sudo /sbin/service xinetd start
 or
service xinetd restart
/etc/init.d/xinetd start

Just see start [OK]

4. Check whether the tftp service is enabled

netstat -a | grep tftp

The display result is UDP 0 *: tftp *: * indicating that the service has been started, indicating that tftp configuration is successful.

5. tftp usage

Copy a file to the tftp server directory, and then start the tftp software on the host for a simple test.

tftp 192.168.1.2
tftp>get <download file> 

tftp>put <upload file>
tftp>q

6. The tftp command is used as follows

tftp your-ip-address

Enter TFTP operation:

  • Connect: connect to a remote tftp server
  • Mode: file transfer mode
  • put: upload file
  • get: download files
  • quit: exit
  • verbose: displays detailed processing information
  • tarce: displays the package path
  • Display current status information: Status
  • Binary: binary transmission mode
  • ascii: ascii transport mode
  • rexmt: set the timeout of packet transmission
  • Timeout: sets the timeout of retransmission
  • Help: help information
  • ? : Help information

7. If the error "AVC decimal, click icon to view" always appears and the file cannot be transferred, the following modifications need to be made

Modify / etc/sysconfig/selinux, set SELinux to disable, and use the command setenforce0 to make the SELinux configuration file effective.

8. Usage of tftp command in Busybox

The command format is:

tftp [option] ... host [port]

If you want to download or upload files, you must use these option s.

-g Indicates that the file is downloaded (get)
-p Indicates the uploaded file (put)
-l Represents the local file name (local file)
-r Represents the file name of the remote host (remote file)

For example, to download embed expert from the remote host 192.168.1.2, enter the following command

tftp -g -r embedexpert 192.168.1.2

uucico

UUCP file transfer service program

Supplementary notes

Uucico command uucp file transfer service program. Uucico is a file transfer tool used to process uucp or uux sent to the queue. Uucco has two working modes: active mode and subsidiary mode. When in active mode, uucico will call the remote host; In affiliate mode, uucico accepts calls from remote hosts.

grammar

uucico [-cCDefqvwz][-i<type>][-I<file>][-p<Connection port number>][-][-rl][-s<host>][-S<host>][-u<user>][-x<type>][--help]

option

-c or--quiet When no work is performed, do not change the contents of the record file and update the current status.
-C or--ifwork Called when there is work to be executed-s or-S Parameter specifies the host.
-D or--nodetach Do not go offline with the control terminal.
-e or--loop Execute in affiliate mode, and the prompt screen requiring login appears.
-f or--force When an execution error occurs, the host is called again without waiting any time.
-i<type>or--stdin<type> When using a standard input device, specify the type of connection port.
-I<file>--config<file> Specifies the profile to use.
-l or--prompt The prompt screen for login appears.
-p<Connection port number>or-port<Connection port number> Specify the connection port number.
-q or--quiet Do not start uuxqt Service procedures.
-r0 or--slave Start in affiliate mode.
-s<host>or--system<host> Call the specified host.
-u<user>or--login<user> Specify the login user account, and it is not allowed to enter any login account.
-v or--version Displays the version information and ends the program.
-w or--wait In the active mode, when the calling action is executed, the prompt screen requiring login will appear.
-x<type>or-X<type>or outgoing-debug<type> Start the specified debug mode.
-z or--try-next When the execution is unsuccessful, try the next selection without ending the program.
--help Displays help and ends the program.

example

Start the uucco service in active mode. Directly enter the following commands at the command prompt:

uucico-r1

Tip: this command is generally not output.

uupick

Command to process incoming files

Supplementary notes

The uupik command handles the incoming file. When other hosts transfer files in through UUCP, these files can be taken out by using uupik instruction.

grammar

uupick [-v][-I<configuration file>][-s<host>][-x<Hierarchy>][--help]

option

-I<configuration file>or--config<configuration file> Specify the configuration file.
-s<host>or--system<host> Process files transferred from the specified host.
-v or--version Displays version information.
--help Display help.

example

Process the files transmitted from the host localhost. Directly enter the following command on the command line:

uupick-s localhost

This command usually has no output.

uuto

Transfer files to remote UUCP host

Supplementary notes

The uuto command is a script file, which will actually execute uucp, which is used to transfer the file to the remote uucp host, and notify the users on the remote host by email after completing the work.

grammar

uuto [file][objective]

example

Transfer the file to the tmp directory of localhost of the remote UUCP host, and directly enter the following command in the command prompt:

uuto./testfile localhost/tmp # Transfer the file to the tmp directory of localhost of the remote UUCP host 

This command usually has no output.

Keywords: Linux

Added by pcjackson06 on Sun, 20 Feb 2022 01:03:55 +0200