1. FTP service operation command
1. Check whether the host has installed the ftp service
rpm -qa | grep ftp
This command is suitable for centos system and will display the ftp version.
which vsftpd
The ftp installation directory will be displayed.
[root@VM000000814 /]# rpm -qa | grep ftp
ftp-0.17-54.el6.x86_64
vsftpd-2.2.2-24.el6.x86_64
[root@VM000000814 /]# which vsftpd
/usr/sbin/vsftpd
[root@VM000000814 /]#
2, start, restart, close the ftp service.
(1), start the ftp service
service vsftpd start
/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
(2), restart the ftp service
service vsftpd restart
(3), close the ftp service
service vsftpd stop
[root@VM000000814 /]#
[root@VM000000814 /]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]
[root@VM000000814 /]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@VM000000814 /]# service vsftpd stop
Shutting down vsftpd: [ OK ]
[root@VM000000814 /]# /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
[root@VM000000814 /]#
[root@VM000000814 /]#
3. View the status of the ftp service
service vsftpd status
show running pid
ps -aux | grep ftp
Display service startup information
[root@VM000000814 /]# service vsftpd status
vsftpd (pid 11092) is running...
[root@VM000000814 /]#
[root@VM000000814 /]#
[root@VM000000814 /]# ps -aux | grep ftp
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 11092 0.0 0.0 52556 804 ? Ss 11:18 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 11200 0.0 0.0 103252 836 pts/0 S+ 11:19 0:00 grep ftp
[root@VM000000814 /]#
Second, ftp use command
cd local directory
ftp -niv <<- EOF
open ftp service ip
user username password
ascii(or bin) //ftp transfer mode, ASSCII mode and binary mode
cd ftp server's target file directory
put file name (or get file name) //get download file, put upload file
bye
EOF
Three, lftp operation ftp command
Generally, ftp cannot directly move folders. If you want to ftp the entire folder at once, you need to traverse and obtain one by one, which is more troublesome. Here is the lftp command, which supports folder download. (If there are multiple files, it is recommended to pack them and get them at one time).
cd localhost target directory
lftp username:password@ftp service ip:port number<<EOF
cd ftp server host target directory
//get file //download file
//get -c file//allow breakpoint resuming download file
//pget -c -n count file//allow count threads, breakpoint resuming download file
//mget file//download file
mirror folder //download target folder and its subfolders
//put file//upload file
//mput file//upload file
mirror -R folder//transfer local folder and its subfolders are uploaded to the ftp server in reverse.
bye
EOF
Below is the script to download a folder.
#ftp服务ip
host="172.21.4.33"
#ftp服务端口,默认21
port="21"
#ftp账号
user="thb"
#ftp密码
pwd="12qeq"
#演示下载文件夹/test/files/
homepath='/test/'
echo $homepath
#如果本机/test/目录不存在,则创建该目录
if [ ! -d $homepath ]
then
mkdir $homepath
fi
#目标文件夹
targetpath='files'
echo $targetpath
#切换本地/test/目录
cd $homepath
#连接ftp服务
lftp $user:$pwd@$host:$port <<EOF
#切换ftp服务器的/test/目录
cd $homepath
#下载目标文件夹
mirror $targetpath
bye
EOF
Fourth, lftp operation sftp command
The connection establishment methods are different, but the operations are similar. Here is just one method for recording backup.
lftp -u sftp username, sftp password sftp://sftp service ip <<EOF
//Set to allow overwriting of existing files
set xfer:clobber on
//Switch sftp service host directory
lcd target directory
//download file
get target file
bye
EOF