版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
文檔簡易的FTP軟件文檔目 錄一、需求分析 31.1 用戶需求 31.2 功能需求 31.3 性能需求 3二、概要設(shè)計(jì) 32.1 主要模塊功能描述 32.2 整體結(jié)構(gòu)模塊圖 42.3 流程圖 5三、詳細(xì)設(shè)計(jì) 53.1 界面模塊實(shí)現(xiàn) 53.2 模塊功能調(diào)用 113.3 功能函數(shù)編寫及實(shí)現(xiàn)效果 11四、調(diào)試分析 14五、測試結(jié)果 15六、課程設(shè)計(jì)總結(jié) 20七、參考文獻(xiàn) 21八、附錄 21文檔一、需求分析1.1用戶需求實(shí)現(xiàn)一個(gè)簡易的 FTP軟件,要現(xiàn)FTP常用的功能,包括列文件目錄,下載文件,上傳文件,用戶登錄 /注銷等。1.2功能需求該系統(tǒng)主要包括: 1.可視化的交互界面模塊; 2.連接服務(wù)器用戶登錄模塊; 3.瀏覽服務(wù)器/本地目錄和文件模塊; 4.上傳/下載文件模塊; 5.目錄操作模塊。1.3性能需求整個(gè)系統(tǒng)操作應(yīng)當(dāng)簡便,界面友好,運(yùn)行穩(wěn)定,執(zhí)行速度快。系統(tǒng)本身運(yùn)行對計(jì)算機(jī)硬件平臺和操作系統(tǒng)平臺要求適中。二、概要設(shè)計(jì)2.1主要模塊功能描述本次課程設(shè)計(jì)的簡易FTP軟件需要具備一些基本功能模塊,如連接、上傳、下載等,其中最主要的功能模塊如下:1、下載功能模塊:連接用戶指定的FTP服務(wù)器,獲取服務(wù)器目錄下的文件列表,當(dāng)用戶選擇項(xiàng)目為文件時(shí),點(diǎn)擊下載可以下載用戶所需要的文件。選定文件后提示用戶將文件存儲在何處,用戶選擇存儲區(qū)后開始下載任務(wù)。依靠FTP協(xié)議的支持,用戶下載的文件沒有類型和大小限制, 即用戶可已選擇任何自己想要下載的文件,通過 FTP客戶端進(jìn)行下載。2、上傳功能模塊:用戶可以自行選擇本機(jī)上存儲的文件,上傳至 FTP服務(wù)器。在用戶選擇存儲在服務(wù)器的位置后,點(diǎn)擊上傳,選擇所需要上傳的文件,即可將文件上傳至服務(wù)器。3、連接功能模塊:將用戶本機(jī)與指定的IP地址連接,驗(yàn)證用戶命和密碼,在FTP服務(wù)器上進(jìn)行注冊。4、目錄操作模塊:連接用戶指定的 FTP服務(wù)器,可以創(chuàng)建或刪除文件夾,文檔也可以通過更改遠(yuǎn)程工作目錄改變該用戶的根目錄。2.2整體結(jié)構(gòu)模塊圖客戶在啟動(dòng)客戶端程序后輸入相應(yīng)的登陸信息就能連接到服務(wù)器上,對服務(wù)器上的文件進(jìn)行瀏覽、新建、刪除、重命名、上傳、下載文件等操作,通過斷開結(jié)束與服務(wù)器的連接。文檔2.3流程圖三、詳細(xì)設(shè)計(jì)本次課程設(shè)計(jì)的界面顯示通過 mainframe類實(shí)現(xiàn),所有界面相關(guān)定義、布局等以及各功能模塊的調(diào)用都在 mainframe類中編寫。各功能定義及實(shí)現(xiàn)則在 ftpfunction類中編寫。3.1界面模塊實(shí)現(xiàn)由于各界面編寫過程中代碼太多并且源代碼已在結(jié)尾附上,在此以登陸界面為例,以下是對登錄界面按鈕、輸入框等的布局。登陸界面源代碼:文檔jLabel1.setText("jLabel1");jLabel2.setText("用戶名:");jLabel3.setText("密碼:");jButton1.setText("登陸");jButton1ActionPerformed(evt);}});jButton2.setText("連接服務(wù)器}});jLabel6.setText("遠(yuǎn)處服務(wù)器地址: ");jTextField5.setText("localhost");}});jLabel7.setText("端口號:");文檔jTextField6.setText("21");宋體",1,12));jLabel8.setText("注意:請先連接服務(wù)器再登陸 ");jButton6.setText("斷開連接");jButton6ActionPerformed(evt);}}); jPanel1Layout = newjPanel1.setLayout(jPanel1Layout);.addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(javax.swing.addGroup(jPanel1Layout.createSequentialGroup().addGap(117,117,117).addGroup(jPanel1Layout.createParallelGroup(ja.addComponent(jLabel2).addComponent(jLabel3)).addGap(18,18,18).addGroup(jPanel1Layout.createParallelGroup(ja文檔.addComponent(jTextField2,.addComponent(jTextField1,.addGroup(jPanel1Layout.createSequentialGroup().addGap(123,123,123).addComponent(jLabel7).addGap(18,18,18).addComponent(jTextField6,.addGroup(jPanel1Layout.createSequentialGroup().addGap(55,55,55).addGroup(jPanel1Layout.createParallelGroup(ja.addComponent(jLabel8).addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel6).addGap(37,37,37).addComponent(jTextField5,.addGap(94,94,94)).addGroup(jPanel1Layout.createSequentialGroup().addGap(193,193,193).addComponent(jButton1)).addGroup(jPanel1Layout.createSequentialGroup().addGap(184,184,184).addComponent(jButton2)文檔cement.RELATED,27,Short.MAX_VALUE).addComponent(jButton6).addGap(5,5,5))).addGap(119,119,119)));jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel8).addComponent(jLabel6).addComponent(jTextField5, .addGap(28,28,28).addComponent(jLabel7).addComponent(jTextField6, .addGap(13,13,13)文檔.addComponent(jButton2).addComponent(jButton6)).addGap(18,18,18).addComponent(jLabel2).addComponent(jTextField1, .addGap(18,18,18).addComponent(jLabel3).addComponent(jTextField2,.addGap(18,18,18).addComponent(jButton1).addGap(98,98,98)));jTabbedPane1.addTab("登陸",jPanel1);用戶登錄界面顯示如下圖:文檔3.2模塊功能調(diào)用在mainframe類中定義的各按鈕通過對ftpfunction類中的函數(shù)進(jìn)行調(diào)用實(shí)現(xiàn)各自功能,以下是對各模塊按鈕在運(yùn)行過程中調(diào)用函數(shù)的編寫。由于按鈕太多并且源代碼已在結(jié)尾附上,在此以用戶登錄過程中的函數(shù)調(diào)用為例:在用戶登錄界面過調(diào)用FtpFunction類中的setUser、setPW、login三個(gè)函數(shù)實(shí)現(xiàn)用戶的登錄。{Stringuser=jTextField1.getText().toString();Stringpw=jTextField2.getText().toString();FtpFunction.setUser(user);FtpFunction.setPW(pw);FtpFunction.login();}3.3功能函數(shù)編寫及實(shí)現(xiàn)效果在ftpfunction 類中創(chuàng)建并定義了各個(gè)模塊的功能函數(shù), 由于定義函數(shù)太多并且源代碼已在結(jié)尾附上,在此以登陸時(shí)所需用到的 login函數(shù)為例,以下為login函數(shù)的源代碼:publicvoidlogin(){try{文檔if(connectSocket==null){JOptionPane.showConfirmDialog(null,服務(wù)器尚未連接,請先連接!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);return;}sendCommand("USER"+user);response=readLine();if(!response.startsWith("331")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯(cuò)誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);用戶名或密碼錯(cuò)誤! "+response);return;}sendCommand("PASS"+passWord);response=readLine();if(!response.startsWith("230")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯(cuò)誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);用戶名或密碼錯(cuò)誤! "+response);return;文檔}logined=true;JOptionPane.showConfirmDialog(null,登陸成功!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);cwd(remotePath);}catch(Exceptione){JOptionPane.showConfirmDialog(null,登陸失?。?,登陸信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);}}如果在服務(wù)器尚未連接的情況下登陸,則會顯示如下界面:如果用戶名或密碼輸入錯(cuò)誤,則會顯示如下界面:文檔在連接服務(wù)器后,且用戶名和密碼都輸入成功的情況下,會顯示如下界面:四、調(diào)試分析此建議
FTP軟件在
U-FTPsrv運(yùn)行情況下作出測試, 結(jié)果基本能夠達(dá)到預(yù)期功能,
滿足用戶的基本的登錄服務(wù)器,上傳下載數(shù)據(jù)的需求,并且在
Windows
平臺上經(jīng)測試能夠穩(wěn)定的運(yùn)行。不足之處在于上傳下載過程中無法得知過程進(jìn)度、剩余時(shí)間等信息,對用戶上傳較大文件時(shí)會造成一定的不方便,能加入斷點(diǎn)傳輸?shù)脑挄?。總的來說,測試容較少,可能會存在一些 BUG,與現(xiàn)實(shí)生活家使用的那些 FTP下載軟件有相當(dāng)?shù)木嚯x。對此,還更應(yīng)該的深入的學(xué)習(xí) Java語言中的那多重要的類庫,更全面的了解他們的功能,文檔爭取完善其功能。五、測試結(jié)果輸入服務(wù)器的 IP地址,默認(rèn)端口號為 21,連接服務(wù)器:服務(wù)器連接成功后,輸入用戶名和登錄密碼:所登陸用戶的詳細(xì)信息:輸入要上傳的文件路徑,點(diǎn)擊上傳進(jìn)行上傳:文檔上傳前該用戶的文件夾:上傳成功后該用戶的文件夾:瀏覽服務(wù)器地址中該用戶的工作目錄:文檔顯示當(dāng)前目錄,顯示在了框中,如下圖:在當(dāng)前目錄中創(chuàng)建文件夾 123,該用戶工作目錄的文件夾中出現(xiàn)名為 123的文件夾,可見于下面截圖的左下角:文檔刪除名為123的文件夾,該文件夾在用戶的工作目錄的文件夾中刪除,下面截圖的左下角:
同樣可見于改變該用戶的工作目錄,截圖中為改為A為當(dāng)前用戶的工作目錄,通過顯示當(dāng)前工作目錄可以知道更改工作目錄成功,也可以通過顯示遠(yuǎn)程文件列表驗(yàn)證是否成功:文檔輸入所需下載的文件路徑和下載后存放的路徑進(jìn)行下載:下圖可見2.doc下載成功:通過斷開連接可同時(shí)進(jìn)行斷開服務(wù)器連接和用戶注銷:文檔六、課程設(shè)計(jì)總結(jié)通過翻閱書籍,在網(wǎng)上查閱資料,實(shí)踐編程等一系列進(jìn)程,一個(gè)簡易的 FTP客戶端軟件的設(shè)計(jì)與開發(fā)終于完成了,雖然功能上還有許多不足,但通過這些時(shí)間的鉆研,從擬定方案,設(shè)計(jì)模塊,解決開發(fā)過程中遇到的各種困難,最終實(shí)現(xiàn)了該文件傳輸系統(tǒng)的基本功能。實(shí)現(xiàn)了遠(yuǎn)程登錄服務(wù)器、瀏覽本地與服務(wù)器目錄文件和數(shù)據(jù)上傳下載等功能需求,從而實(shí)現(xiàn)了一個(gè)簡易的FTP客戶端軟件。通過自己實(shí)際設(shè)計(jì)并開發(fā)一個(gè)FTP客戶端軟件,使我了解了C/S開發(fā)模式和FTP的發(fā)展歷史及工作原理,對FTP協(xié)議在網(wǎng)絡(luò)中的結(jié)構(gòu)和本身協(xié)議在傳輸?shù)淖饔糜辛烁畹恼J(rèn)識。通過系統(tǒng)測試,我又了解了軟件測試的理論知識,理解了測試的概念,了解了測試方法以及過程,雖然只是很有限的嘗試和使用,但我盡量通過所學(xué)的知識從中尋找錯(cuò)誤和不足,也對我今后做類似項(xiàng)目起到了積極的指導(dǎo)作用,總的說來此次課題我受益頗豐。遇到的問題是剛開始輸入文件進(jìn)行上傳下載的格式總是不正確,導(dǎo)致一段時(shí)間的焦慮和止步不前,但通過查閱資料,對輸入的格式有了更加清晰的認(rèn)知,終于解決了這個(gè)問題。我們在遇到問題時(shí),要積極查閱資料或者和老師同學(xué)進(jìn)行探討,對基礎(chǔ)知識一定要掌握的非常牢靠,才能不出現(xiàn)一些小問題。隨著計(jì)算機(jī)網(wǎng)絡(luò)的迅猛發(fā)展,計(jì)算機(jī)網(wǎng)絡(luò)的應(yīng)用日益廣泛,并且已經(jīng)滲透到生活的方方面面,對人們的生活起著不可忽視的作用。在這個(gè)信息化的社會中,了解網(wǎng)絡(luò)是當(dāng)代大學(xué)生必不可少的一門課程。尤其是對我們信息專業(yè)的學(xué)生,認(rèn)識計(jì)算機(jī)網(wǎng)絡(luò)的基本理論,以及其在生活中發(fā)揮的重大作用,為今后我們進(jìn)一步深入學(xué)習(xí)專業(yè)課程,奠定了良好的基礎(chǔ)。 科學(xué)技術(shù)日新月異蓬勃發(fā)展,從20世紀(jì)90年代初迅速發(fā)展起來的文檔internet,已經(jīng)飛速改變了人們的生活和工作。人們被其豐富無窮的信息資源、方便快捷的交流方式深深吸引。如今計(jì)算機(jī)網(wǎng)絡(luò)的教育更是早已深入大學(xué)校園,尤其是對于我們信息管理與信息系統(tǒng)這個(gè)專業(yè),網(wǎng)絡(luò)是信息傳播、資源共享的重要媒介,這門課程也是我們必不可少的一課。隨著計(jì)算機(jī)技術(shù)的迅猛發(fā)展,計(jì)算機(jī)的應(yīng)用逐漸滲透到各個(gè)技術(shù)領(lǐng)域和整個(gè)社會的各個(gè)方面。社會的信息化、數(shù)據(jù)的分布處理、各種計(jì)算機(jī)資源的共享等各種應(yīng)用要求都推動(dòng)計(jì)算機(jī)技術(shù)朝著群體化方向發(fā)展,促使計(jì)算機(jī)技術(shù)與通信技術(shù)緊密結(jié)合。網(wǎng)絡(luò)是計(jì)算機(jī)的一個(gè)群體,是由多臺計(jì)算機(jī)組成的,這些計(jì)算機(jī)是通過一定的通信介質(zhì)互連在一起的, 計(jì)算機(jī)之間的互連是指它們彼此之間能夠交換信息。 計(jì)算機(jī)網(wǎng)絡(luò)屬于多機(jī)系統(tǒng)的疇, 是計(jì)算機(jī)和通信這兩大現(xiàn)代技術(shù)相結(jié)合的產(chǎn)物, 它代表著當(dāng)前計(jì)算機(jī)體系結(jié)構(gòu)發(fā)展的一個(gè)重要方向。計(jì)算機(jī)網(wǎng)絡(luò)技術(shù)的發(fā)展和普及日益改變著我們的學(xué)習(xí)和生活,各種各樣的網(wǎng)絡(luò)應(yīng)用讓我們眼花繚亂,因特網(wǎng)讓我們真正體會到信息爆炸的威力。七、參考文獻(xiàn)HerbertSchildt.Java實(shí)用教程[M].:清華大學(xué),2005。月,葉曙光,徐飪.Jbuilder9入門與提高[M].:科學(xué),2004。耿祥義,躍平.JAVA2實(shí)用教程(第二版)[M].:清華大學(xué),2004。[4]樹林,潔萍.JAVA語言最新實(shí)用案例教程 [M].:科學(xué),2006。W.RichardStevens.TCP/IP詳解卷1:協(xié)議[M].:機(jī)械工業(yè),2000。曉明.計(jì)算機(jī)網(wǎng)絡(luò)編程技術(shù)[M].:中國鐵道,2009。八、附錄Mainframe 類:文檔ftpFunctionFtpFunction=newftpFunction();/**CreatesnewformmainFrame*/publicmainFrame(){setTitle("ftp 客戶端");setLocation(250,150);initComponents();}privatevoidinitComponents(){文檔jLabel1.setText("jLabel1");jLabel2.setText(" 用戶名:");jLabel3.setText(" 密碼:");jButton1.setText(" 登陸");文檔jButton1ActionPerformed(evt);}});jButton2.setText(" 連接服務(wù)器");jButton2ActionPerformed(evt);}});jLabel6.setText(" 遠(yuǎn)處服務(wù)器地址: ");jTextField5.setText("localhost");jTextField5ActionPerformed(evt);}});jLabel7.setText(" 端口號:");jTextField6.setText("21"); 宋體",1,12));jLabel8.setText(" 注意:請先連接服務(wù)器再登陸 ");jButton6.setText(" 斷開連接");jButton6ActionPerformed(evt);}});文檔
jPanel1Layout
=
newjPanel1.setLayout(jPanel1Layout);jPanel1Layout.setHorizontalGroup(.addGroup(jPanel1Layout.createSequentialGroup().Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createSequentialGroup().addGap(117,117,117).addGroup(jPanel1Layout.createParallelGroup(javax.s.addComponent(jLabel2).addComponent(jLabel3)).addGap(18,18,18).addGroup(jPanel1Layout.createParallelGroup(javax.s.addComponent(jTextField2,.addComponent(jTextField1,.addGroup(jPanel1Layout.createSequentialGroup().addGap(123,123,123).addComponent(jLabel7).addGap(18,18,18).addComponent(jTextField6,文檔.addGroup(jPanel1Layout.createSequentialGroup().addGap(55,55,55).addGroup(jPanel1Layout.createParallelGroup(javax.s.addComponent(jLabel8).addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel6).addGap(37,37,37).addComponent(jTextField5, 112,.addGap(94,94,94)).addGroup(jPanel1Layout.createSequentialGroup().addGap(193,193,193).addComponent(jButton1)).addGroup(jPanel1Layout.createSequentialGroup().addGap(184,184,184).addComponent(jButton2)ent.RELATED,27,Short.MAX_VALUE).addComponent(jButton6).addGap(5,5,5))).addGap(119,119,119)));jPanel1Layout.setVerticalGroup(文檔jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel8)TED,11,Short.MAX_VALUE).Alignment.BASELINE).addComponent(jLabel6).addComponent(jTextField5, .addGap(28,28,28).Alignment.BASELINE).addComponent(jLabel7).addComponent(jTextField6, .addGap(13,13,13).Alignment.BASELINE).addComponent(jButton2).addComponent(jButton6)).addGap(18,18,18).Alignment.BASELINE).addComponent(jLabel2).addComponent(jTextField1, 文檔.addGap(18,18,18).Alignment.BASELINE).addComponent(jLabel3).addComponent(jTextField2, .addGap(18,18,18).addComponent(jButton1).addGap(98,98,98)));jTabbedPane1.addTab(" 登陸",jPanel1);jLabel4.setText(" 文件路徑:");jButton3.setText(" 上傳");jButton3ActionPerformed(evt);}});
jPanel2Layout
=
newjPanel2.setLayout(jPanel2Layout);jPanel2Layout.setHorizontalGroup(.addGroup(jPanel2Layout.createSequentialGroup().addGap(48,48,48).addComponent(jLabel4).addGap(42,42,42)文檔.addComponent(jTextField3,.addGap(36,36,36).addComponent(jButton3).addContainerGap(82,Short.MAX_VALUE)));jPanel2Layout.setVerticalGroup(.addGroup(jPanel2Layout.createSequentialGroup().addGap(37,37,37).Alignment.BASELINE).addComponent(jLabel4).addComponent(jTextField3, .addComponent(jButton3)).addContainerGap(301,Short.MAX_VALUE)));jTabbedPane1.addTab(" 上傳文件",jPanel2);jTextArea1.setColumns(20);jTextArea1.setRows(5);jScrollPane1.setViewportView(jTextArea1);jButton5.setText(" 顯示遠(yuǎn)程文件列表 ");jButton5ActionPerformed(evt);}});文檔jLabel11.setText(" 所需下載的文件路徑: ");jLabel12.setText(" 下載后存放路徑: ");jButton9.setText(" 下載");jButton9ActionPerformed(evt);}});
jPanel3Layout
=
newjPanel3.setLayout(jPanel3Layout);jPanel3Layout.setHorizontalGroup(.addGroup(jPanel3Layout.createSequentialGroup().Alignment.LEADING,false).addGroup(jPanel3Layout.createSequentialGroup().addGap(35,35,35).addComponent(jButton5).addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout.createParallelGroup(javax.s.addComponent(jLabel11).addComponent(jLabel12)).addGap(18,18,18).addGroup(jPanel3Layout.createParallelGroup(javax.s文檔.addComponent(jTextField10).addComponent(jTextField9,.addComponent(jButton9)))).addGroup(jPanel3Layout.createSequentialGroup().addGap(50,50,50).addComponent(jScrollPane1, 379,.addContainerGap(84,Short.MAX_VALUE)));jPanel3Layout.setVerticalGroup(.addGroup(jPanel3Layout.createSequentialGroup().addGap(25,25,25).addComponent(jButton5)LATED).addComponent(jScrollPane1, 184,.addGap(18,18,18).Alignment.BASELINE).addComponent(jLabel11).addComponent(jTextField9,文檔 .addGap(18,18,18).Alignment.BASELINE).addComponent(jLabel12).addComponent(jTextField10, .addComponent(jButton9)).addContainerGap(37,Short.MAX_VALUE)));jTabbedPane1.addTab(" 下載文件",jPanel3);jLabel5.setText(" 創(chuàng)建目錄:");jButton4.setText(" 創(chuàng)建");jButton4ActionPerformed(evt);}});jLabel9.setText(" 當(dāng)前目錄:");jButton7.setText(" 顯示");jButton7ActionPerformed(evt);}});jLabel10.setText(" 刪除目錄:");jButton8.setText(" 刪除");文檔jButton8ActionPerformed(evt);}});jLabel13.setText(" 改變遠(yuǎn)程工作目錄: ");jButton10.setText(" 改變目錄");jButton10ActionPerformed(evt);}});
jPanel4Layout
=
newjPanel4.setLayout(jPanel4Layout);jPanel4Layout.setHorizontalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel4Layout.createSequentialGroup().addGap(78,78,78).addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel13).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jTextField11,javax.swing.GroupLayout.PREFERRED_SIZE,137,文檔.addGap(18,18,18).addComponent(jButton10)).addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel5)ntPlacement.UNRELATED).addComponent(jTextField4, 125,.addGroup(jPanel4Layout.createParallelGroup(javax.swinING,jPanel4Layout.createSequentialGroup().addComponent(jLabel10).addGap(18,18,18).addComponent(jTextField8))ING,jPanel4Layout.createSequentialGroup().addComponent(jLabel9).addGap(18,18,18).addComponent(jTextField7, 116,.addGap(35,35,35)文檔.addComponent(jButton7).addComponent(jButton4).addComponent(jButton8)))).addContainerGap(85,Short.MAX_VALUE)));jPanel4Layout.setVerticalGroup(.addGroup(jPanel4Layout.createSequentialGroup().addGap(34,34,34).Alignment.BASELINE).addComponent(jLabel5).addComponent(jTextField4, .addComponent(jButton4)).addGap(27,27,27).Alignment.BASELINE).addComponent(jLabel9).addComponent(jTextField7, .addComponent(jButton7)).addGap(38,38,38).Alignment.BASELINE).addComponent(jLabel10).addComponent(jTextField8,文檔 .addComponent(jButton8)).addGap(37,37,37).Alignment.BASELINE).addComponent(jLabel13).addComponent(jTextField11, .addComponent(jButton10)).addContainerGap(127,Short.MAX_VALUE)));jTabbedPane1.addTab(" 目錄操作",jPanel4); layout = newgetContentPane().setLayout(layout);layout.setHorizontalGroup(.addComponent(jTabbedPane1, 522,Short.MAX_VALUE));layout.setVerticalGroup(.addComponent(jTabbedPane1, 393,Short.MAX_VALUE));pack();文檔}//</editor-fold>//GEN-END:initComponents用戶登陸按鈕private void evt){//GEN-FIRST:event_jButton1ActionPerformedStringuser=jTextField1.getText().toString();Stringpw=jTextField2.getText().toString();FtpFunction.setUser(user);FtpFunction.setPW(pw);FtpFunction.login();}//GEN-LAST:event_jButton1ActionPerformed連接服務(wù)器private void
evt){//GEN-FIRST:event_jButton2ActionPerformedStringremoteHost=jTextField5.getText().toString();intremotePort=Integer .parseInt(jTextField6.getText().toString());FtpFunction.setRemoteHost(remoteHost);FtpFunction.setRemotePort(remotePort);FtpFunction.connect();}//GEN-LAST:event_jButton2ActionPerformedprivate void
evt){//GEN-FIRST:event_jTextField5ActionPerformed//TODOaddyourhandlingcodehere:}//GEN-LAST:event_jTextField5ActionPerformed文件上傳private void evt){//GEN-FIRST:event_jButton3ActionPerformedStringlocalFileName=jTextField3.getText().toString();文檔try{FtpFunction.upload(localFileName);}catch(IOExceptionex){}}//GEN-LAST:event_jButton3ActionPerformed下載文件按鈕private void evt){//GEN-FIRST:event_jButton9ActionPerformedStringremoteFile=jTextField9.getText().toString();StringlocalFile=jTextField10.getText().toString();try{FtpFunction.download(remoteFile,localFile);}catch(IOExceptionex){}}//GEN-LAST:event_jButton9ActionPerformed顯示遠(yuǎn)程文件列表private void evt){//GEN-FIRST:event_jButton5ActionPerformedtry{ArrayList<String>fileList=FtpFunction.list("");for(inti=0;i<fileList.size();i++){jTextArea1.setText(jTextArea1.getText().toString()+fileList.get(i)+"\n");}}catch(IOExceptionex){}文檔}//GEN-LAST:event_jButton5ActionPerformed創(chuàng)建目錄private void evt){//GEN-FIRST:event_jButton4ActionPerformedStringdirName=jTextField4.getText().toString();try{FtpFunction.mkdir(dirName);}catch(IOExceptionex){}}//GEN-LAST:event_jButton4ActionPerformed斷開連接private void evt){//GEN-FIRST:event_jButton6ActionPerformedtry{FtpFunction.close();}catch(IOExceptionex){}JOptionPane.showConfirmDialog(null,成功斷開連接!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);}//GEN-LAST:event_jButton6ActionPerformed顯示當(dāng)前目錄private void evt){//GEN-FIRST:event_jButton7ActionPerformedtry{Stringdir=FtpFunction.pwd();文檔if(dir!=null){jTextField7.setText(dir);}else{jTextField7.setText(" 當(dāng)前目錄為根目錄 ");}}catch(IOExceptionex){}}//GEN-LAST:event_jButton7ActionPerformed更改遠(yuǎn)程工作目錄private void evt){//GEN-FIRST:event_jButton10ActionPerformedtry{Stringdir=jTextField11.getText().toString();FtpFunction.cwd(dir);}catch(IOExceptionex){}}//GEN-LAST:event_jButton10ActionPerformed刪除目錄private void evt){//GEN-FIRST:event_jButton8ActionPerformedtry{FtpFunction.rmdir(jTextField8.getText().toString());//GEN-LAST:event_jButton8ActionPerformed}catch(IOExceptionex){}文檔}顯示當(dāng)前遠(yuǎn)程目錄/**paramargsthecommandlinearguments*/publicstaticvoidmain(Stringargs[]){publicvoidrun(){newmainFrame().setVisible(true);}});}文檔//Endofvariablesdeclaration//GEN-END:variables}Ftpfunction 類:文檔publicclassftpFunction{privateSocketconnectSocket;// 控制連接,用于傳送和響應(yīng)命令privateSocketdataSocket;// 數(shù)據(jù)連接,用于數(shù)據(jù)傳輸privateBufferedReaderinData;// 控制連接中用于讀取返回信息的數(shù)據(jù)流privateBufferedWriteroutData;//控制連接中用于傳送用戶命令的數(shù)據(jù)流privateStringresponse=null;//將返回信息封裝成字符串privateStringremoteHost;//遠(yuǎn)程主機(jī)名privateintremotePort;//通信端口號privateStringremotePath;//遠(yuǎn)程路徑privateStringuser;//用戶名privateStringpassWord;//用戶口令FilerootPath=newFile("/");//根路徑FilecurrentPath=rootPath;//當(dāng)前路徑privatebooleanlogined;//判斷是否登錄服務(wù)器的標(biāo)志privatebooleandebug;publicftpFunction(){remoteHost="localhost";remotePort=21;remotePath="/";user="user";passWord="123";logined=false;debug=false;}設(shè)置服務(wù)器域名(IP地址)publicvoidsetRemoteHost(StringremoteHost){this.remoteHost=remoteHost;文檔}返回服務(wù)器域名(IP地址)publicStringgetRemoteHost(){returnremoteHost;}設(shè)置端口publicvoidsetRemotePort(intremotePort){this.remotePort=remotePort;}返回端口publicintgetRemotePort(){returnremotePort;}//TheremotedirectorypathpublicvoidsetRemotePath(StringremotePath){this.remotePath=remotePath;}Thecurrentremotedirectorypath.publicStringgetRemotePath(){returnremotePath;}//用戶名publicvoidsetUser(Stringuser){this.user=user;}密碼publicvoidsetPW(Stringpassword){this.passWord=password;}publicvoidsetDebug(booleandebug){文檔this.debug=debug;}publicSocketconnect(){try{if(connectSocket==null){connectSocket=newSocket(remoteHost,remotePort);inData = new BufferedReader(newInputStreamReader(connectSocket.getInputStream()));// 輸入信息(字符輸入流)outData = new BufferedWriter(newOutputStreamWriter(connectSocket.getOutputStream()));// 輸出信息(字符輸出流)}response=readLine();JOptionPane.showConfirmDialog(null,服務(wù)器已經(jīng)成功連接",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);}catch(Exceptione){JOptionPane.showConfirmDialog(null,連接失敗",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);}returnconnectSocket;}publicvoidlogin(){try{if(connectSocket==null){文檔JOptionPane.showConfirmDialog(null,"服務(wù)器尚未連接,請先連接! ",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);return;}sendCommand("USER"+user);response=readLine();if(!response.startsWith("331")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯(cuò)誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE); 用戶名或密碼錯(cuò)誤! "+response);return;}sendCommand("PASS"+passWord);response=readLine();if(!response.startsWith("230")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯(cuò)誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE); 用戶名或密碼錯(cuò)誤! "+response);return;}文檔logined=true;JOptionPane.showConfirmDialog(null,登陸成功!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);cwd(remotePath);}catch(Exceptione){JOptionPane.showConfirmDialog(null,登陸失??!",登陸信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);}}獲取遠(yuǎn)程服務(wù)器的目錄列表publicArrayList<String>list(Stringmask)throwsIOException{if(!logined){ 服務(wù)器尚未連接。 ");//login();}ArrayList<String>fileList=newArrayList<String>();try{dataSocket=createDataSocket();if(mask==null||mask.equals("")||mask.equals("")){sendCommand("LIST");}else{sendCommand("LIST"+mask);}response=readLine();if(!response.startsWith("1")){文檔}BufferedReader dataIn = new BufferedReader(newInputStreamReader(dataSocket.getInputStream()));Stringline;while((line=dataIn.readLine())!=null){fileList.add(line);}dataIn.close();// 關(guān)閉數(shù)據(jù)流dataSocket.close();// 關(guān)閉數(shù)據(jù)連接response=readLine();}catch(IOExceptionioex){ioex.printStackTrace();}catch(Exceptionex){ex.printStackTrace();}returnfileList;}///ClosetheFTPconnection.退出登錄并終止連接QUITpublicsynchronizedvoidclose()throwsIOException{try{sendCommand("QUIT");}finally{cleanup();正在關(guān)閉......");}}文檔privatevoidcleanup(){try{inData.close();outData.close();connectSocket.close();//connectSocket=null;logined=false;}catch(Exceptionex){ex.printStackTrace();}}///Ifthevalueofmodeistrue,setbinarymodefordownloads.Else,setAsciimode.//////publicvoidsetBinaryMode(Booleanmode)throwsIOException{if(mode){sendCommand("TYPEI");}else{sendCommand("TYPEA");}response=readLine();if(!response.startsWith("200")){thrownewIOException("CaughtError"+response);}}//顯示當(dāng)前遠(yuǎn)程工作目錄 PWD文檔publicsynchronizedStringpwd()throwsIOException{sendCommand("XPWD");Stringdir=null;response=readLine();if(response.startsWith("257")){ //服務(wù)器響應(yīng)信息如: 257"/C:/TEMP/"iscurrentdirectory. 截取兩引號之間的容intfristQuote=response.indexOf('\"');intsecondQuote=response.indexOf('\"',fristQuote+1);if(secondQuote>0){dir=response.substring(fristQuote+1,secondQuote);}}returndir;}//CWD 改變遠(yuǎn)程系統(tǒng)的工作目錄publicsynchronizedbooleancwd(Stringdir)throwsIOException{if(dir.equals("/")){// 根路徑 當(dāng)前路徑是根目錄! ");}if(!logined){login();}sendCommand("CWD"+dir);response=readLine();if(response.startsWith("250")){returntrue;}else{returnfalse;}文檔}上傳文件publicsynchronizedbooleanupload(StringlocalFileName)throwsIOException{dataSocket=createDataSocket();inti=localFileName.lastIndexOf("/");if(i==-1){i=localFileName.lastIndexOf("\\");}Stringelement_1="";if(i!=-1){element_1=localFileName.substring(i+1);}sendCommand("STOR"+element_1);response=readLine();if(!response.startsWith("1")){}FileInputStreamdataIn=newFileInputStream(localFileName);BufferedOutputStream dataOut = newBufferedOutputStream(dataSocket.getOutputStream());byte[]buffer=newbyte[4096];intbytesRead=0;do{bytesRead=dataIn.read(buffer);if(bytesRead!=-1){dataOut.write(buffer ,0,bytesRead);}}while(bytesRead!=-1);dataOut.flush();dataOut.close();文檔dataIn.close();dataSocket.close();// 關(guān)閉此數(shù)據(jù)連接response=readLine();if(response.startsWith("226")){JOptionPane.showConfirmDialog(null,文件上傳成功!",上傳信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);}return(response.startsWith("226"));}//下載文件 RETRpublic synchronized boolean download(String remoteFile, String localFile) throwsIOException{dataSocket=createDataSocket();sendCommand("RETR"+remoteFile);response=readLine();if(!response.startsWith("1")){}BufferedInputStream dataIn = newBuffere
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度勞動(dòng)合同終止及員工安置補(bǔ)償協(xié)議2篇
- 二零二五年度戶外廣告牌安裝與城市形象宣傳合同3篇
- 二零二五年度個(gè)人商鋪買賣合同協(xié)議
- 二零二五年度國際貿(mào)易政策分析與市場進(jìn)入咨詢合同
- 2025年度個(gè)人房屋裝修貸款合同7篇
- 2025年度內(nèi)控制度咨詢與內(nèi)部控制流程再造合同
- 二零二五年度協(xié)議離婚財(cái)產(chǎn)清算與分配專業(yè)合同3篇
- 2025年度農(nóng)業(yè)生態(tài)環(huán)境保護(hù)與補(bǔ)償合同3篇
- 2025年度摩托車租賃與賽事運(yùn)營管理合同3篇
- 二零二五版鎳礦市場準(zhǔn)入與資質(zhì)認(rèn)證合同4篇
- 2024版義務(wù)教育小學(xué)數(shù)學(xué)課程標(biāo)準(zhǔn)
- 智能護(hù)理:人工智能助力的醫(yī)療創(chuàng)新
- 國家中小學(xué)智慧教育平臺培訓(xùn)專題講座
- 5G+教育5G技術(shù)在智慧校園教育專網(wǎng)系統(tǒng)的應(yīng)用
- 服務(wù)人員隊(duì)伍穩(wěn)定措施
- VI設(shè)計(jì)輔助圖形設(shè)計(jì)
- 淺談小學(xué)勞動(dòng)教育的開展與探究 論文
- 2023年全國4月高等教育自學(xué)考試管理學(xué)原理00054試題及答案新編
- 河北省大學(xué)生調(diào)研河北社會調(diào)查活動(dòng)項(xiàng)目申請書
- JJG 921-2021環(huán)境振動(dòng)分析儀
- 兩段焙燒除砷技術(shù)簡介 - 文字版(1)(2)課件
評論
0/150
提交評論