一、连接FTP服务器
连接FTP服务器可用 ftp+空格+服务器地址 的格式,例如:
ftp example.com ftp 192.168.0.1 ftp user@example.com
如果连接成功,将会返回状态码220+服务器信息,例如(仅为示例):
Connected to ****. 220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 5 of 1000 allowed. 220-Local time is now 10:26. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity.
二、登录FTP服务器
服务器接下来会询问用户名密码信息。
如果匿名登录,可使用用户名’anonymous’和空密码。
登陆成功后会返回状态码230+服务器信息,例如(仅为示例):
230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files.
三、目录操作
FTP目录操作与本地目录操作基本无异。
1.ls打印目录列表:
ftp> ls
返回(仅为示例):
200 PORT command successful 150 Connecting to port ***** …… …… 226-Options: -a -l 226 40 matches total
2.cd改变目录:
ftp> cd 目录名
返回(仅为示例):
250 OK. Current directory is 目录名
3.mkdir创建文件夹
四、下载文件
1.首先用lcd命令设置下载位置,默认为当前文件夹。
lcd 目录名
返回(仅为示例):
Local directory now 目录名
2.用get命令下载单个文件
get 文件名
返回(仅为示例):
local: 文件名 remote: 文件名 200 PORT command successful 150-Connecting to port **** 150 42233.8 kbytes to download 226-File successfully transferred 226 8.824 seconds (measured here), 4.67 Mbytes per second 43247387 bytes received in 8.96 secs (4712.5 kB/s)
3.用mget命令下载多个文件
mget *.mp3
则下载所有后缀为.mp3的文件
五、上传文件
1.用put命令上传单个文件
put 文件名
或使用绝对路径
put /路径/文件名
2.用mput命令上传多个文件
mput *.mp3
则上传所有后缀为.mp3的文件
六、关闭FTP连接
文件传输完成后,安全起见,需关闭连接。
使用bye exit quit三个命令都可以关闭连接
返回(仅为示例):
221-Goodbye. You uploaded 0 and downloaded 42234 kbytes. 221 Logout.
发表回复