※ 引述《vrgigi.bbs@bbs.mgt.ncu.edu.tw (夏傑)》之銘言:
> 有沒有人會用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