本人初学Java,希望大家提供下源码,及我应该学习的有关FTP资料,或者有用Java编写FTP简单服务器的流程图(中文版)。
谢谢,本人邮箱[email protected]
个人感觉编写该程序应该需要Java的网络编程,线程,流,套接字的知识
因未找到详细介绍有关FTP编写的方法,故发此贴,希望大家多多指教!
谢谢,本人邮箱[email protected]
个人感觉编写该程序应该需要Java的网络编程,线程,流,套接字的知识
因未找到详细介绍有关FTP编写的方法,故发此贴,希望大家多多指教!
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String servlet_name="/servlets/data/";
String downloadfilepath=svrinfo_u.get_info().getProperty("downloadfilepath");
//get the file path by the method of the "replaceAll"
String filePath=req.getRequestURI().replaceAll(servlet_name, downloadfilepath);
String[][] fileNTD = null;
File file = new File(filePath);
if(file.isFile()){
//start the doDownload
doDownload(req,res,filePath);
}else{
//list the file
fileNTD=readFolderByFile(filePath);
}
}
}
private void doDownload(HttpServletRequest req, HttpServletResponse res,String downloadfilepath) throws IOException{
String cacheTime="0";
File file = new File(downloadfilepath);
res.setHeader("Location",downloadfilepath);
res.setHeader("Cache-Control", "max-age=" + cacheTime);
res.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
OutputStream outputStream = res.getOutputStream();
InputStream inputStream = new FileInputStream(downloadfilepath);
byte[] buffer = new byte[1024];
int i = -1;
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i);
}
outputStream.flush();
outputStream.close();
inputStream.close();
outputStream = null;
}