資源簡介
基于java的FTP客戶端設計與實現,實現服務器的登陸,上傳與下載文件等基本功能

代碼片段和文件信息
/*
?*?To?change?this?template?choose?Tools?|?Templates
?*?and?open?the?template?in?the?editor.
?*/
package?ftp;
import?java.net.Socket;
import?java.io.*;
import?java.util.*;
import?javax.swing.JOptionPane;
/**
?*
?*?@author?Administrator
?*/
public?class?ftpFunction?{
????private?Socket?connectSocket;//控制連接,用于傳送和響應命令
????private?Socket?dataSocket;//數據連接,用于數據傳輸
????private?BufferedReader?inData;//控制連接中用于讀取返回信息的數據流
????private?BufferedWriter?outData;//控制連接中用于傳送用戶命令的數據流
????private?String?response?=?null;//將返回信息封裝成字符串
????private?String?remoteHost;//遠程主機名
????private?int?remotePort;//通信端口號
????private?String?remotePath;//遠程路徑
????private?String?user;//用戶名
????private?String?passWord;//用戶口令
????File?rootPath?=?new?File(“/“);//根路徑
????File?currentPath?=?rootPath;//當前路徑
????private?boolean?logined;//判斷是否登錄服務器的標志
????private?boolean?debug;
????public?ftpFunction()?{
????????remoteHost?=?“localhost“;
????????remotePort?=?21;
????????remotePath?=?“/“;
????????user?=?“user“;
????????passWord?=?“123“;
????????logined?=?false;
????????debug?=?false;
????}
????//設置服務器域名(IP地址)
????public?void?setRemoteHost(String?remoteHost)?{
????????this.remoteHost?=?remoteHost;
????}
????//返回服務器域名(IP地址)
????public?String?getRemoteHost()?{
????????return?remoteHost;
????}
????//設置端口
????public?void?setRemotePort(int?remotePort)?{
????????this.remotePort?=?remotePort;
????}
????//返回端口
????public?int?getRemotePort()?{
????????return?remotePort;
????}
????//The?remote?directory?path
????public?void?setRemotePath(String?remotePath)?{
????????this.remotePath?=?remotePath;
????}
????///?The?current?remote?directory?path.
????public?String?getRemotePath()?{
????????return?remotePath;
????}
????//用戶名
????public?void?setUser(String?user)?{
????????this.user?=?user;
????}
????//密碼
????public?void?setPW(String?password)?{
????????this.passWord?=?password;
????}
????public?void?setDebug(boolean?debug)?{
????????this.debug?=?debug;
????}
????public?Socket?connect()?{
????????try?{
????????????if?(connectSocket?==?null)?{
????????????????connectSocket?=?new?Socket(remoteHost?remotePort);
????????????????inData?=?new?BufferedReader(new?InputStreamReader(connectSocket.getInputStream()));//輸入信息(字符輸入流)
????????????????outData?=?new?BufferedWriter(new?OutputStreamWriter(connectSocket.getOutputStream()));//輸出信息(字符輸出流)
????????????}
????????????response?=?readLine();
??????????JOptionPane.showConfirmDialog(null
????????????????????“服務器已經成功連接“
????????????????????“連接信息“?JOptionPane.CLOSED_OPTION
????????????????????JOptionPane.INFORMATION_MESSAGE);
????????}?catch?(Exception?e)?{???????????
?????????????JOptionPane.showConfirmDialog(null
????????????????????“?連接失敗“
????????????????????“?連接信息“?JOptionPane.CLOSED_OPTION
????????????????????JOptionPane.INFORMATION_MESSAGE);
????????}
????????return?connectSocket;
????}
????public?void?login()?{
????????try?{
????????????if?(connectSocket?==?null)?{
????????????????JOptionPane.showConfirmDialog(null
????????????????????“?服務器尚未連接
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-04-14?22:25??ftp\
?????文件???????????3??2009-05-26?22:32??ftp\3.txt
?????文件???????????3??2009-05-26?22:30??ftp\4.txt
?????目錄???????????0??2009-05-27?08:11??ftp\build\
?????文件????????3346??2009-05-26?12:13??ftp\build.xm
?????目錄???????????0??2015-03-22?15:56??ftp\build\classes\
?????目錄???????????0??2009-05-27?08:11??ftp\build\classes\classes\
?????文件????????9990??2009-05-26?23:09??ftp\build\classes\classes\ftpFunction.class
?????文件?????????363??2009-05-26?18:49??ftp\build\classes\classes\Main.class
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????717??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????718??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????523??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件?????????715??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件???????14231??2009-05-26?23:09??ftp\build\classes\classes\mainfr
?????文件???????45720??2015-04-01?20:39??ftp\FILE?TRANSFER?PROTOCOL.pdf
?????文件??????891408??2015-04-01?20:52??ftp\File?Transfer?Protocols.pdf
?????文件??????428215??2015-04-14?22:25??ftp\FTP客戶端設計與實現.doc
?????目錄???????????0??2015-03-28?13:48??ftp\ll\
?????文件??????????85??2009-05-26?12:13??ftp\manifest.mf
?????目錄???????????0??2009-05-27?08:11??ftp\nbproject\
?????文件???????33192??2009-05-26?12:13??ftp\nbproject\build-impl.xm
?????文件?????????455??2009-05-26?12:13??ftp\nbproject\genfiles.properties
?????目錄???????????0??2009-05-27?08:11??ftp\nbproject\private\
............此處省略12個文件信息
評論
共有 條評論