




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
文檔簡易的FTP軟件文檔目 錄一、需求分析 31.1 用戶需求 31.2 功能需求 31.3 性能需求 3二、概要設計 32.1 主要模塊功能描述 32.2 整體結構模塊圖 42.3 流程圖 5三、詳細設計 53.1 界面模塊實現(xiàn) 53.2 模塊功能調用 113.3 功能函數(shù)編寫及實現(xiàn)效果 11四、調試分析 14五、測試結果 15六、課程設計總結 20七、參考文獻 21八、附錄 21文檔一、需求分析1.1用戶需求實現(xiàn)一個簡易的 FTP軟件,要現(xiàn)FTP常用的功能,包括列文件目錄,下載文件,上傳文件,用戶登錄 /注銷等。1.2功能需求該系統(tǒng)主要包括: 1.可視化的交互界面模塊; 2.連接服務器用戶登錄模塊; 3.瀏覽服務器/本地目錄和文件模塊; 4.上傳/下載文件模塊; 5.目錄操作模塊。1.3性能需求整個系統(tǒng)操作應當簡便,界面友好,運行穩(wěn)定,執(zhí)行速度快。系統(tǒng)本身運行對計算機硬件平臺和操作系統(tǒng)平臺要求適中。二、概要設計2.1主要模塊功能描述本次課程設計的簡易FTP軟件需要具備一些基本功能模塊,如連接、上傳、下載等,其中最主要的功能模塊如下:1、下載功能模塊:連接用戶指定的FTP服務器,獲取服務器目錄下的文件列表,當用戶選擇項目為文件時,點擊下載可以下載用戶所需要的文件。選定文件后提示用戶將文件存儲在何處,用戶選擇存儲區(qū)后開始下載任務。依靠FTP協(xié)議的支持,用戶下載的文件沒有類型和大小限制, 即用戶可已選擇任何自己想要下載的文件,通過 FTP客戶端進行下載。2、上傳功能模塊:用戶可以自行選擇本機上存儲的文件,上傳至 FTP服務器。在用戶選擇存儲在服務器的位置后,點擊上傳,選擇所需要上傳的文件,即可將文件上傳至服務器。3、連接功能模塊:將用戶本機與指定的IP地址連接,驗證用戶命和密碼,在FTP服務器上進行注冊。4、目錄操作模塊:連接用戶指定的 FTP服務器,可以創(chuàng)建或刪除文件夾,文檔也可以通過更改遠程工作目錄改變該用戶的根目錄。2.2整體結構模塊圖客戶在啟動客戶端程序后輸入相應的登陸信息就能連接到服務器上,對服務器上的文件進行瀏覽、新建、刪除、重命名、上傳、下載文件等操作,通過斷開結束與服務器的連接。文檔2.3流程圖三、詳細設計本次課程設計的界面顯示通過 mainframe類實現(xiàn),所有界面相關定義、布局等以及各功能模塊的調用都在 mainframe類中編寫。各功能定義及實現(xiàn)則在 ftpfunction類中編寫。3.1界面模塊實現(xiàn)由于各界面編寫過程中代碼太多并且源代碼已在結尾附上,在此以登陸界面為例,以下是對登錄界面按鈕、輸入框等的布局。登陸界面源代碼:文檔jLabel1.setText("jLabel1");jLabel2.setText("用戶名:");jLabel3.setText("密碼:");jButton1.setText("登陸");jButton1ActionPerformed(evt);}});jButton2.setText("連接服務器}});jLabel6.setText("遠處服務器地址: ");jTextField5.setText("localhost");}});jLabel7.setText("端口號:");文檔jTextField6.setText("21");宋體",1,12));jLabel8.setText("注意:請先連接服務器再登陸 ");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模塊功能調用在mainframe類中定義的各按鈕通過對ftpfunction類中的函數(shù)進行調用實現(xiàn)各自功能,以下是對各模塊按鈕在運行過程中調用函數(shù)的編寫。由于按鈕太多并且源代碼已在結尾附上,在此以用戶登錄過程中的函數(shù)調用為例:在用戶登錄界面過調用FtpFunction類中的setUser、setPW、login三個函數(shù)實現(xiàn)用戶的登錄。{Stringuser=jTextField1.getText().toString();Stringpw=jTextField2.getText().toString();FtpFunction.setUser(user);FtpFunction.setPW(pw);FtpFunction.login();}3.3功能函數(shù)編寫及實現(xiàn)效果在ftpfunction 類中創(chuàng)建并定義了各個模塊的功能函數(shù), 由于定義函數(shù)太多并且源代碼已在結尾附上,在此以登陸時所需用到的 login函數(shù)為例,以下為login函數(shù)的源代碼:publicvoidlogin(){try{文檔if(connectSocket==null){JOptionPane.showConfirmDialog(null,服務器尚未連接,請先連接!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);return;}sendCommand("USER"+user);response=readLine();if(!response.startsWith("331")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);用戶名或密碼錯誤! "+response);return;}sendCommand("PASS"+passWord);response=readLine();if(!response.startsWith("230")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);用戶名或密碼錯誤! "+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);}}如果在服務器尚未連接的情況下登陸,則會顯示如下界面:如果用戶名或密碼輸入錯誤,則會顯示如下界面:文檔在連接服務器后,且用戶名和密碼都輸入成功的情況下,會顯示如下界面:四、調試分析此建議
FTP軟件在
U-FTPsrv運行情況下作出測試, 結果基本能夠達到預期功能,
滿足用戶的基本的登錄服務器,上傳下載數(shù)據(jù)的需求,并且在
Windows
平臺上經測試能夠穩(wěn)定的運行。不足之處在于上傳下載過程中無法得知過程進度、剩余時間等信息,對用戶上傳較大文件時會造成一定的不方便,能加入斷點傳輸?shù)脑挄???偟膩碚f,測試容較少,可能會存在一些 BUG,與現(xiàn)實生活家使用的那些 FTP下載軟件有相當?shù)木嚯x。對此,還更應該的深入的學習 Java語言中的那多重要的類庫,更全面的了解他們的功能,文檔爭取完善其功能。五、測試結果輸入服務器的 IP地址,默認端口號為 21,連接服務器:服務器連接成功后,輸入用戶名和登錄密碼:所登陸用戶的詳細信息:輸入要上傳的文件路徑,點擊上傳進行上傳:文檔上傳前該用戶的文件夾:上傳成功后該用戶的文件夾:瀏覽服務器地址中該用戶的工作目錄:文檔顯示當前目錄,顯示在了框中,如下圖:在當前目錄中創(chuàng)建文件夾 123,該用戶工作目錄的文件夾中出現(xiàn)名為 123的文件夾,可見于下面截圖的左下角:文檔刪除名為123的文件夾,該文件夾在用戶的工作目錄的文件夾中刪除,下面截圖的左下角:
同樣可見于改變該用戶的工作目錄,截圖中為改為A為當前用戶的工作目錄,通過顯示當前工作目錄可以知道更改工作目錄成功,也可以通過顯示遠程文件列表驗證是否成功:文檔輸入所需下載的文件路徑和下載后存放的路徑進行下載:下圖可見2.doc下載成功:通過斷開連接可同時進行斷開服務器連接和用戶注銷:文檔六、課程設計總結通過翻閱書籍,在網上查閱資料,實踐編程等一系列進程,一個簡易的 FTP客戶端軟件的設計與開發(fā)終于完成了,雖然功能上還有許多不足,但通過這些時間的鉆研,從擬定方案,設計模塊,解決開發(fā)過程中遇到的各種困難,最終實現(xiàn)了該文件傳輸系統(tǒng)的基本功能。實現(xiàn)了遠程登錄服務器、瀏覽本地與服務器目錄文件和數(shù)據(jù)上傳下載等功能需求,從而實現(xiàn)了一個簡易的FTP客戶端軟件。通過自己實際設計并開發(fā)一個FTP客戶端軟件,使我了解了C/S開發(fā)模式和FTP的發(fā)展歷史及工作原理,對FTP協(xié)議在網絡中的結構和本身協(xié)議在傳輸?shù)淖饔糜辛烁畹恼J識。通過系統(tǒng)測試,我又了解了軟件測試的理論知識,理解了測試的概念,了解了測試方法以及過程,雖然只是很有限的嘗試和使用,但我盡量通過所學的知識從中尋找錯誤和不足,也對我今后做類似項目起到了積極的指導作用,總的說來此次課題我受益頗豐。遇到的問題是剛開始輸入文件進行上傳下載的格式總是不正確,導致一段時間的焦慮和止步不前,但通過查閱資料,對輸入的格式有了更加清晰的認知,終于解決了這個問題。我們在遇到問題時,要積極查閱資料或者和老師同學進行探討,對基礎知識一定要掌握的非常牢靠,才能不出現(xiàn)一些小問題。隨著計算機網絡的迅猛發(fā)展,計算機網絡的應用日益廣泛,并且已經滲透到生活的方方面面,對人們的生活起著不可忽視的作用。在這個信息化的社會中,了解網絡是當代大學生必不可少的一門課程。尤其是對我們信息專業(yè)的學生,認識計算機網絡的基本理論,以及其在生活中發(fā)揮的重大作用,為今后我們進一步深入學習專業(yè)課程,奠定了良好的基礎。 科學技術日新月異蓬勃發(fā)展,從20世紀90年代初迅速發(fā)展起來的文檔internet,已經飛速改變了人們的生活和工作。人們被其豐富無窮的信息資源、方便快捷的交流方式深深吸引。如今計算機網絡的教育更是早已深入大學校園,尤其是對于我們信息管理與信息系統(tǒng)這個專業(yè),網絡是信息傳播、資源共享的重要媒介,這門課程也是我們必不可少的一課。隨著計算機技術的迅猛發(fā)展,計算機的應用逐漸滲透到各個技術領域和整個社會的各個方面。社會的信息化、數(shù)據(jù)的分布處理、各種計算機資源的共享等各種應用要求都推動計算機技術朝著群體化方向發(fā)展,促使計算機技術與通信技術緊密結合。網絡是計算機的一個群體,是由多臺計算機組成的,這些計算機是通過一定的通信介質互連在一起的, 計算機之間的互連是指它們彼此之間能夠交換信息。 計算機網絡屬于多機系統(tǒng)的疇, 是計算機和通信這兩大現(xiàn)代技術相結合的產物, 它代表著當前計算機體系結構發(fā)展的一個重要方向。計算機網絡技術的發(fā)展和普及日益改變著我們的學習和生活,各種各樣的網絡應用讓我們眼花繚亂,因特網讓我們真正體會到信息爆炸的威力。七、參考文獻HerbertSchildt.Java實用教程[M].:清華大學,2005。月,葉曙光,徐飪.Jbuilder9入門與提高[M].:科學,2004。耿祥義,躍平.JAVA2實用教程(第二版)[M].:清華大學,2004。[4]樹林,潔萍.JAVA語言最新實用案例教程 [M].:科學,2006。W.RichardStevens.TCP/IP詳解卷1:協(xié)議[M].:機械工業(yè),2000。曉明.計算機網絡編程技術[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(" 連接服務器");jButton2ActionPerformed(evt);}});jLabel6.setText(" 遠處服務器地址: ");jTextField5.setText("localhost");jTextField5ActionPerformed(evt);}});jLabel7.setText(" 端口號:");jTextField6.setText("21"); 宋體",1,12));jLabel8.setText(" 注意:請先連接服務器再登陸 ");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(" 顯示遠程文件列表 ");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(" 當前目錄:");jButton7.setText(" 顯示");jButton7ActionPerformed(evt);}});jLabel10.setText(" 刪除目錄:");jButton8.setText(" 刪除");文檔jButton8ActionPerformed(evt);}});jLabel13.setText(" 改變遠程工作目錄: ");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連接服務器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顯示遠程文件列表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顯示當前目錄private void evt){//GEN-FIRST:event_jButton7ActionPerformedtry{Stringdir=FtpFunction.pwd();文檔if(dir!=null){jTextField7.setText(dir);}else{jTextField7.setText(" 當前目錄為根目錄 ");}}catch(IOExceptionex){}}//GEN-LAST:event_jButton7ActionPerformed更改遠程工作目錄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){}文檔}顯示當前遠程目錄/**paramargsthecommandlinearguments*/publicstaticvoidmain(Stringargs[]){publicvoidrun(){newmainFrame().setVisible(true);}});}文檔//Endofvariablesdeclaration//GEN-END:variables}Ftpfunction 類:文檔publicclassftpFunction{privateSocketconnectSocket;// 控制連接,用于傳送和響應命令privateSocketdataSocket;// 數(shù)據(jù)連接,用于數(shù)據(jù)傳輸privateBufferedReaderinData;// 控制連接中用于讀取返回信息的數(shù)據(jù)流privateBufferedWriteroutData;//控制連接中用于傳送用戶命令的數(shù)據(jù)流privateStringresponse=null;//將返回信息封裝成字符串privateStringremoteHost;//遠程主機名privateintremotePort;//通信端口號privateStringremotePath;//遠程路徑privateStringuser;//用戶名privateStringpassWord;//用戶口令FilerootPath=newFile("/");//根路徑FilecurrentPath=rootPath;//當前路徑privatebooleanlogined;//判斷是否登錄服務器的標志privatebooleandebug;publicftpFunction(){remoteHost="localhost";remotePort=21;remotePath="/";user="user";passWord="123";logined=false;debug=false;}設置服務器域名(IP地址)publicvoidsetRemoteHost(StringremoteHost){this.remoteHost=remoteHost;文檔}返回服務器域名(IP地址)publicStringgetRemoteHost(){returnremoteHost;}設置端口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,服務器已經成功連接",連接信息",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,"服務器尚未連接,請先連接! ",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);return;}sendCommand("USER"+user);response=readLine();if(!response.startsWith("331")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE); 用戶名或密碼錯誤! "+response);return;}sendCommand("PASS"+passWord);response=readLine();if(!response.startsWith("230")){cleanup();JOptionPane.showConfirmDialog(null,用戶名或密碼錯誤!",連接信息",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE); 用戶名或密碼錯誤! "+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);}}獲取遠程服務器的目錄列表publicArrayList<String>list(Stringmask)throwsIOException{if(!logined){ 服務器尚未連接。 ");//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();// 關閉數(shù)據(jù)流dataSocket.close();// 關閉數(shù)據(jù)連接response=readLine();}catch(IOExceptionioex){ioex.printStackTrace();}catch(Exceptionex){ex.printStackTrace();}returnfileList;}///ClosetheFTPconnection.退出登錄并終止連接QUITpublicsynchronizedvoidclose()throwsIOException{try{sendCommand("QUIT");}finally{cleanup();正在關閉......");}}文檔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);}}//顯示當前遠程工作目錄 PWD文檔publicsynchronizedStringpwd()throwsIOException{sendCommand("XPWD");Stringdir=null;response=readLine();if(response.startsWith("257")){ //服務器響應信息如: 257"/C:/TEMP/"iscurrentdirectory. 截取兩引號之間的容intfristQuote=response.indexOf('\"');intsecondQuote=response.indexOf('\"',fristQuote+1);if(secondQuote>0){dir=response.substring(fristQuote+1,secondQuote);}}returndir;}//CWD 改變遠程系統(tǒng)的工作目錄publicsynchronizedbooleancwd(Stringdir)throwsIOException{if(dir.equals("/")){// 根路徑 當前路徑是根目錄! ");}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();// 關閉此數(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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2023-2024學年人教版高中信息技術必修二第三章第三節(jié)《 信息系統(tǒng)中的軟件》教學設計
- 大型礦山爆破拆除作業(yè)合同
- 跨區(qū)域藝術表演團體巡回演出合同標準文本
- 跨境流動資金借款合同書
- 購銷合同權利義務轉讓協(xié)議
- 1認識光 教學設計-2023-2024學年科學五年級上冊青島版
- 10 牛郎織女(一)第二課時 教學設計-2024-2025學年語文五年級上冊統(tǒng)編版
- 住酒店合同范本
- Module 2 public holidays unit 2 教學設計- 2024-2025學年外研版九年級英語上冊
- 沐足合同范本
- 天津2025年天津中德應用技術大學輔導員崗位招聘7人筆試歷年參考題庫附帶答案詳解
- 2025年湘西民族職業(yè)技術學院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 2025年湖南交通職業(yè)技術學院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 部編人教版道德與法治九年級下冊全冊課件
- 三維電生理導航系統(tǒng)技術參數(shù)
- 三年級下冊科學活動手冊
- 《交通工程CAD》課程教學大綱(本科)
- 人教版數(shù)學五年級下冊 全冊各單元教材解析
- 換班申請表(標準模版)
- 者陰村戰(zhàn)友紀念者陰山對越自衛(wèi)還擊作戰(zhàn)30周年聯(lián)誼會計劃2
- 承插型盤扣式支模架專項施工方案
評論
0/150
提交評論