看板java
标 题Re: 如何写一个ftp client的小程式呢~要能上下传档案 写不出来
发信站SayYA 资讯站 (Tue Mar 13 18:29:04 2007)
转信站ptt!ctu-reader!news.nctu!SayYa
※ 引述《[email protected] (夏杰)》之铭言:
> 有没有人会用java写client端的ftp小程式
> 要能上下传档案及list目录
先学会传指令,再学会抓档。
RFC 959 里说了,ftp 是以 telnet 为基础的。
所以你可以先找个 ftp 用 telnet 去用看看
=================================================
[slayer@rat slayer]$ telnet ftp.debian.org 21
Trying 128.101.240.212...
Connected to ftp.debian.org.
Escape character is '^]'.
220 saens.debian.org FTP server (vsftpd)
USER xd
530 This FTP server is anonymous only.
USER anonymous
331 Please specify the password.
PASS xd
230-
230-This site is just another one in a worldwide array of Debian mirrors.
230-It is not the "primary Debian FTP site" -- it is merely an official
230-mirror that is in the United States of America.
230-
230-If you are connecting from outside the USA, please consider using another
230-official Debian mirror, one that is closer to you. This will likely help
230-you by speeding up your downloads, and it will help us by lessening the
230-load on this machine.
230-
230-Current list of Debian mirrors is at
http://www.debian.org/mirror/list
230-
230 Login successful.
=================================================================
以上完成了使用者登入,黄字部分是俺自己KEY的。
接着您试着打列出目录
=================================================================
LIST
425 Use PORT or PASV first.
=================================================================
这 Server 还真好心,提醒我们没有指定 PORT 或是宣告 PASV
至少这二者的差别是您的功课了。
俺先以 PASV 为示范
=================================================================
PASV
227 Entering Passive Mode (128,101,240,212,155,72)
=================================================================
Server端给了你一组IP,PORT
让你另外可以另外开始连线下载LIST的结果
128,101,240,212 是IP
155,72 是 port。 <---> 怎麽换算也是您的作业 :P
您可以写一个小程式开 Socket 去接 LIST 的结果
另外档案下载也就是一样了
BTW. 请您阅读 RFC959 或相关讨论和弄明白什麽是 PI, DTP
大致上 FTP 就能写出来又有概念噜。实作这个是很有趣滴
--
※ Origin: SayYA 资讯站 <bbs.sayya.org>
◆ From: 218-161-121-243.dynamic.hinet.net