通过应用服务器下载FTP服务器上的文件? 我今天尝试在tomcat上架构个应用,B/S模式,用户通过jsp 下载FTP服务器上的文件到客户端,是否可以行。 今天下载的文件都到tomcat架构的服务器上了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static boolean downFile(String remotePath,String fileName,String localPath) { boolean success = false; FTPClient ftp = new FTPClient(); try { int reply; String url = "192.168.*.*"; Integer port = 21; String username = "anonymous"; String password = ""; ftp.connect(url, port); ftp.login(username, password);//登录 reply = ftp.getReplyCode(); //此段为了能下载带有中文名字的文件 ftp.setControlEncoding("GBK"); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); conf.setServerLanguageCode("zh"); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); return success; } ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录 ftp.enterLocalPassiveMode(); //不加此段系统一直在等待中 FTPFile[] fs = ftp.listFiles(); for(FTPFile ff:fs){ if(ff.getName().equals(fileName)){ File localFile = new File(localPath+"\\"+ff.getName()); OutputStream is = new FileOutputStream(localFile); ftp.retrieveFile(ff.getName(), is); is.close(); } } ftp.logout(); success = true; } catch (IOException e) { e.printStackTrace(); } finally { if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException ioe) { } } } return success; }} 我就是通过FTPCLIENT实现FTP下载的,但是下载的是装有TOMCAT的应用服务器,并不是浏览器端。 先把文件用流读进来,然后直接把流写到response中去,设置response的contextType为file 请问下做过resin服务器的日志备份问 关于java中输出HTML代码的问题 jspsmartload文件上传问题 购物车怎么样实现购物?? 关于汉字乱码问题 用HashMap 执行 Insert into 语句-的错误=-望指点一二……三 jstl怎么实现for(int)循环 请问有人知道在什么网站上可以申请到免费的支持jsp的个人空间吗 弹出对话框? 关于<s:if>标签的问题 js中iframe的位置问题 使用httpclient忽略ssl证书访问网站出错java.security.NoSuchAlgorithmException
boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
String url = "192.168.*.*";
Integer port = 21;
String username = "anonymous";
String password = "";
ftp.connect(url, port);
ftp.login(username, password);//登录
reply = ftp.getReplyCode();
//此段为了能下载带有中文名字的文件
ftp.setControlEncoding("GBK");
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
conf.setServerLanguageCode("zh");
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录
ftp.enterLocalPassiveMode(); //不加此段系统一直在等待中
FTPFile[] fs = ftp.listFiles();
for(FTPFile ff:fs){
if(ff.getName().equals(fileName)){
File localFile = new File(localPath+"\\"+ff.getName());
OutputStream is = new FileOutputStream(localFile);
ftp.retrieveFile(ff.getName(), is);
is.close();
}
}
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}}