由于公司设置了三层交换设置,导致直接拷贝非常卡顿,
所以本人专门写了ftp服务端(匿名登录)
package pan;
import java.util.ArrayList;
import java.util.List;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;
public class RocFtpServer {
public static void main(String[] args) {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory factory = new ListenerFactory();
//设置监听端口
factory.setPort(2121);
//替换默认监听
serverFactory.addListener("default", factory.createListener());
//用户名
BaseUser user = new BaseUser();
user.setName("anonymous");//
// user.setName("gly");
//密码 如果不设置密码就是匿名用户//anonymous
// user.setPassword("123");
//用户主目录
user.setHomeDirectory("E:\BaiduNetdiskDownload");
List<Authority> authorities = new ArrayList<Authority>();
//增加写权限
authorities.add(new WritePermission());
user.setAuthorities(authorities);
//增加该用户
try {
serverFactory.getUserManager().save(user);
} catch (FtpException e1) {
e1.printStackTrace();
}
/**
* 也可以使用配置文件来管理用户
*/
// PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
// userManagerFactory.setFile(new File("users.properties"));
// serverFactory.setUserManager(userManagerFactory.createUserManager());
FtpServer server = serverFactory.createServer();
try {
server.start();
} catch (FtpException e) {
e.printStackTrace();
}
}
}