FTP是在TCP/IP网络和INTERNET上最早使用的协议之一,它属于网络协议组的应用层。
FTP客户机可以给服务器发出命令来下载文件,上传文件,创建或改变服务器上的目录。
FTP在工作上经常用到,其实主要是上传,下载文件. 下面列出其常用的命令:
01. ftp 192.168.0.1 #输入用户名和密码,登陆ftp服务器
[root@host ~]$ ftp 192.168.0.1
Connected to 127.0.0.1.
220 (vsFTPd 2.2.2)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): ftpuse
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
02. ftp>mkdir test #建test测试目录
257 "/d/vas1/ftpuse/test" created
03. ftp> dir #列出文件及目录,也可以用ls -lart命令
227 Entering Passive Mode (192.168.0.1,175,195).
150 Here comes the directory listing.
drwxr-xr-x 2 500 500 4096 Sep 19 07:22 test
04. ftp> cd test #进入ftp服务器上test目录
250 Directory successfully changed.
05. ftp> lcd /home/test #定位本地的目录
Local directory now /home/test
06. ftp> bin #两种传输的方式:二进制的(binary orbin),ascii(默认)
200 Switching to Binary mode.
07. ftp> put for.py #上传本地文件到ftp服务器
local: for.py remote: for.py
227 Entering Passive Mode (192.168.0.1,186,68).
150 Ok to send data.
226 Transfer complete.
277 bytes sent in 0.0038 seconds (71 Kbytes/s)
08. ftp> get cmmbscmx.zip #下载ftp服务器文件到本地
local: cmmbscmx.zip remote: cmmbscmx.zip
227 Entering Passive Mode (192.168.0.1,168,106).
150 Opening BINARY mode data connection for cmmbscmx.zip (1046670 bytes).
226 Transfer complete.
1046670 bytes received in 2.8 seconds (3.7e+02 Kbytes/s)
09. ftp> !dir #查看本地文件及目录
python shell
10. ftp> lcd ./python #进入下一级目录
11. ftp> cd .. #进入上一级目录
12. ftp> rename for.py f.py #重命名文件
13. ftp> delete for.py #删除文件
14. ftp> rmdir test #删除文件夹,必须确保里面没有文件及文件夹
15. ftp> bye #退出,或者用quit命令
221 Goodbye.
16. ftp> help #帮助,查看所有的命令
Commands may be abbreviated. Commands are:
! cr mdir proxy send
$ delete mget sendport site
account debug mkdir put size
append dir mls pwd status
ascii disconnect mode quit struct
bell form modtime quote system
binary get mput recv sunique
bye glob newer reget tenex
case hash nmap rstatus trace
ccc help nlist rhelp type
cd idle ntrans rename user
cdup image open reset umask
chmod lcd passive restart verbose
clear ls private rmdir ?
close macdef prompt runique
cprotect mdelete protect safe
17. ftp> help rmdir #如果具体某个命令用法,可以再前面加help
rmdir remove directory on the remote machine