• 大小: 1.23MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-23
  • 语言: Java
  • 标签: FTP客户端  

资源简介

基于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.xml
     目录           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\mainframe$1.class
     文件         717  2009-05-26 23:09  ftp\build\classes\classes\mainframe$10.class
     文件         718  2009-05-26 23:09  ftp\build\classes\classes\mainframe$11.class
     文件         523  2009-05-26 23:09  ftp\build\classes\classes\mainframe$12.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$2.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$3.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$4.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$5.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$6.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$7.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$8.class
     文件         715  2009-05-26 23:09  ftp\build\classes\classes\mainframe$9.class
     文件       14231  2009-05-26 23:09  ftp\build\classes\classes\mainframe.class
     文件       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.xml
     文件         455  2009-05-26 12:13  ftp\nbproject\genfiles.properties
     目录           0  2009-05-27 08:11  ftp\nbproject\private\
............此处省略12个文件信息

评论

共有 条评论