package a;import java.awt.BorderLayout;import java.util.ArrayList;import javax.swing.JFileChoos

package a;

import java.awt.BorderLayout;
import java.util.ArrayList;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;

public class Main extends JFrame {
    public Main() throws Exception {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        String dir = "c:\\";
        JFileChooser jfc = new JFileChooser(dir);
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (jfc.showOpenDialog(this) == 0) {
            dir = jfc.getSelectedFile().getAbsolutePath();
        }
        JLabel jl = new JLabel(dir);
        this.add(jl, BorderLayout.NORTH);
        ArrayList<Authority> la = new ArrayList<Authority>();
        WritePermission wp = new WritePermission();
        BaseUser bu = new BaseUser();
        ListenerFactory lf = new ListenerFactory();
        FtpServerFactory fsf = new FtpServerFactory();

        la.add(wp);
        bu.setName("anonymous");
        bu.setPassword(null);
        // bu.setHomeDirectory(dir);
        bu.setAuthorities(la);
        lf.setPort(21);
        fsf.addListener("default", lf.createListener());
        fsf.getUserManager().save(bu);
        FtpServer fs = fsf.createServer();
        fs.start();

    }

    public static void main(String[] args) throws Exception {
        Main m = new Main();
        m.setVisible(true);
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值