package com.publiccms.logic.component;
import static com.publiccms.logic.component.SiteComponent.STATIC_FILE_PATH_RESOURCE;
import static com.publiccms.logic.component.SiteComponent.STATIC_FILE_PATH_WEB;
import static com.publiccms.logic.component.SiteComponent.TASK_FILE_PATH;
import static com.publiccms.logic.component.SiteComponent.TEMPLATE_PATH;
import static com.publiccms.logic.component.SiteComponent.getFullFileName;
import static com.sanluan.common.tools.StreamUtils.write;
import static com.sanluan.common.tools.VerificationUtils.encode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import com.publiccms.entities.sys.SysFtpUser;
import com.publiccms.entities.sys.SysSite;
import com.publiccms.logic.service.sys.SysFtpUserService;
import com.publiccms.logic.service.sys.SysSiteService;
import com.sanluan.common.base.Base;
@Component
public class FtpComponent extends Base {
public static final String DATE_FORMAT = "yyyyMMddHHmmss";
public static final String LIST_DATE_FORMAT = "MMM dd HH:mm";
public static final String LIST_DATE_FORMAT1 = "MMM dd yyyy";
public static final String ROOT = SEPARATOR;
public static final String[] VIRTUAL_FILE_PATHS = { STATIC_FILE_PATH_WEB, STATIC_FILE_PATH_RESOURCE, TASK_FILE_PATH,
TEMPLATE_PATH };
private FtpServer ftpServer;
@Autowired
public void createFtpServer(SysFtpUserService service, SysSiteService siteService, SiteComponent siteComponent,
Environment env) {
if ("true".equalsIgnoreCase(env.getProperty("ftp.enable", "true"))) {
try {
ftpServer = new FtpServer(siteComponent.getRootPath(), 21, service, siteService);
} catch (IOException e) {
log.error("Ftp Start Error :" + e.getMessage());
}
}
}
@PreDestroy
public void close() {
if (notEmpty(ftpServer)) {
ftpServer.stop();
}
}
public class FtpServer implements Runnable {
private SysFtpUserService service;
private SysSiteService siteService;
private ServerSocket serverSocket;
private String rootPath;
public FtpServer(String rootPath, int port, SysFtpUserService service, SysSiteService siteService) throws IOException {
this.rootPath = rootPath;
this.service = service;
this.siteService = siteService;
serverSocket = new ServerSocket(port);
log.info("Ftp Listen on " + port);
new Thread(this).start();
}
public void stop() {
try {
serverSocket.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
@Override
public void run() {
while (!serverSocket.isClosed()) {
try {
new Thread(new FtpHandler(serverSocket.accept(), rootPath, this)).start();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
public SysSite getSite(int siteId) {
return siteService.getEntity(siteId);
}
public SysFtpUser getUser(String username) {
return service.findByName(username);
}
}
class FtpHandler extends Base implements Runnable {
private FtpServer server;
private Socket socket; // 用于控制的套接字
private Socket transportSocket; // 用于传输的套接字
private ServerSocket transportServerSocket; // 用于传输的套接字
private boolean isPasv = false;
private SysFtpUser user;
private SysSite site;
private String userPath;
private String currentPath = ROOT;// 当前目录
private String rootPath; // 根目录
private int state = State.STATE_NEED_USERNAME; // 用户状态标识符,在checkPASS中设置
private BufferedReader input;
private PrintWriter output;
private int type = 0; // 文件类型(ascII 或 bin)
public FtpHandler(Socket socket, String rootPath, FtpServer ftpServer) {
this.socket = socket;
this.rootPath = rootPath;
this.server = ftpServer;
try {
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output = new PrintWriter(socket.getOutputStream(), true);
} catch (IOException e) {
log.error("The ftp server start error:" + e.getMessage());
}
}
@Override
public void run() {
try {
boolean flag = true;
String inputString;
pirnt("332 welcome to ThinServer.");
output.flush();
while (flag && null != (inputString = input.readLine())) {
String command;
String param = BLANK;
int index = inputString.indexOf(BLANK_SPACE);
if (-1 == index) {
command = inputString.toUpperCase();
} else {
command = inputString.substring(0, index).toUpperCase();
if (index < inputString.length()) {
param = inputString.substring(index + 1, inputString.length());
}
}
switch (state) {
case State.STATE_NEED_USERNAME:
flag = checkUsername(command, param);
break;
case State.STATE_NEED_PASSWORD:
flag = checkPassword(command, param);
break;
case State.STATE_READY:
switch (command) {
case "ABOR": // 中断数据连接程序
try {
if (notEmpty(transportSocket)) {
transportSocket.close();
if (isPasv) {
transportServerSocket.close();
}
}
} catch (Exception e) {
pirnt("451 failed to send.");
}
pirnt("421 service unavailable.");
break;
case "ACCT":// 系统特权帐号
pirnt("500 command not supported.");
break;
case "ALLO":// 为服务器上的文件存储器分配字节
pirnt("500 command not supported.");
break;
case "APPE":// 添加文件到服务器同名文件
pirnt("500 command not supported.");
break;
case "CDUP":// 到上一层目录
changeCurrentPath("..");
break;
case "CWD": // 到指定的目录
changeCurrentPath(param);
break;
没有合适的资源?快使用搜索试试~ 我知道了~
MF00387-JAVA后台管理CMS源码.zip
共2000个文件
java:826个
html:418个
js:390个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 157 浏览量
2023-09-18
18:02:06
上传
评论
收藏 19.19MB ZIP 举报
温馨提示
JAVA后台管理系统CMS源码 开发语言 : JAVA 数据库 : MySQL 开发工具 : Eclipse 源码类型 : WebForm 注意:不带技术支持,有帮助文件,虚拟商品,发货不退,看好再拍。 登录账号密码:admin、admin maven工程 数据库脚本在工程中database文件夹下
资源推荐
资源详情
资源评论
收起资源包目录
MF00387-JAVA后台管理CMS源码.zip (2000个子文件)
bootstrap.css 138KB
bootstrap.css 120KB
bootstrap.min.3.3.5.css 120KB
bootstrap.min.css 115KB
ueditor.css 43KB
ueditor.css 43KB
ueditor.css 43KB
font-awesome-ie7.min.css 37KB
font-awesome-ie7.min.css 37KB
ueditor.min.css 34KB
ueditor.min.css 34KB
ueditor.min.css 34KB
core.css 32KB
core.css 32KB
font-awesome.min.css 22KB
font-awesome.min.css 22KB
icomoon.css 22KB
video-js.css 21KB
video-js.css 21KB
video-js.css 21KB
image.css 18KB
image.css 18KB
image.css 18KB
video.css 15KB
video.css 15KB
video.css 15KB
attachment.css 14KB
attachment.css 14KB
attachment.css 14KB
video-js.min.css 11KB
video-js.min.css 11KB
video-js.min.css 11KB
main.css 11KB
style.css 10KB
style.css 8KB
animate-custom.css 8KB
codemirror.css 7KB
codemirror.css 7KB
shCoreDefault.css 7KB
shCoreDefault.css 7KB
shCoreDefault.css 7KB
style.css 6KB
style.css 6KB
style.css 6KB
style.css 6KB
style.css 6KB
style.css 6KB
style.css 6KB
style.css 6KB
owl.transitions.css 4KB
scrawl.css 4KB
scrawl.css 4KB
scrawl.css 4KB
ieHack.css 3KB
ieHack.css 3KB
merge.css 3KB
merge.css 3KB
codemirror.css 3KB
codemirror.css 3KB
lint.css 3KB
lint.css 3KB
codemirror.css 3KB
charts.css 3KB
charts.css 3KB
charts.css 3KB
background.css 2KB
background.css 2KB
background.css 2KB
tern.css 2KB
tern.css 2KB
emotion.css 2KB
emotion.css 2KB
emotion.css 2KB
dialogbase.css 2KB
dialogbase.css 2KB
dialogbase.css 2KB
music.css 2KB
music.css 2KB
music.css 2KB
owl.theme.css 2KB
google.css 2KB
owl.carousel.css 1KB
simplescrollbars.css 1KB
simplescrollbars.css 1KB
edittable.css 1KB
edittable.css 1KB
edittable.css 1KB
template.css 1KB
template.css 1KB
template.css 1KB
product-list.css 949B
login.css 778B
login.css 778B
show-hint.css 662B
show-hint.css 662B
code-formatter.css 659B
code-formatter.css 659B
webuploader.css 515B
webuploader.css 515B
webuploader.css 515B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
jane9872
- 粉丝: 109
- 资源: 7795
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功