javaftp下载所有文件
这个要做定时任务的,ftp不可能主动给你发,只能自己每隔多长时间就去检索一次,应该把ftp文件目录结构和文件名称全部存入数据库,在下载时候对文件的标识状态位陵森进行更新,方便于对文件的判断。然后从ftp下载文件即可。如果需尺汪陪要连陵蠢接ftp下载文件的代码,可以发送邮件到[email protected]
㈡ java如何获取ftp制定目录下所有文件集合(包括文件名称)只要一个方法。
/**
* 取得相对于当前连接目录的某个目录下所有文件列表
*
* @param path
* @return
*/
public List getFileList(String path){
List list = new ArrayList();
DataInputStream dis;
try {
dis = new DataInputStream(ftpClient.nameList(this.path + path));
String filename = "";
while((filename = dis.readLine()) != null){
list.add(filename);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
我从这里拷来的 你不清楚看看里面 http://hi..com/yuanhotel/item/000b6334894d11f42784f4da
满意就采纳 谢谢
㈢ java ftp连接一次下载多个文件
/**
*参考例子如下:
*@paramnamelist下载的文件列表
*@parampath下载路径
*@paramzipname压缩文件名称
*/
publicvoidzipDownloadFile(HttpServletResponseresponse,List<string>namelist,Stringpath,Stringzipname){
byte[]buf=newbyte[1024];
try{
//本地保存设置
response.addHeader("Content-Disposition","attachment;filename="
+URLEncoder.encode(zipname,sysEncoding)+".zip");
response.setContentType("application/x-zip-compressed");
//向本地写文件
ServletOutputStreamsos=response.getOutputStream();
ZipOutputStreamzipOut=newZipOutputStream(newBufferedOutputStream(sos));
for(Stringname:namelist){
ZipEntryentry=newZipEntry(name);
zipOut.putNextEntry(entry);
InputStreambis=this.getStream(path,name);
if(bis!=null){
intreadLen=-1;
while((readLen=bis.read(buf,0,1024))!=-1){
zipOut.write(buf,0,readLen);
}
bis.close();
}
}
zipOut.close();
}catch(Exceptione){
e.printStackTrace();
}
}</string>
㈣ ftp上的中文路径的文件怎么用java下载
正则表达式是十分有用,但是弯基樱在使用时也要付出代价。尤其是在 N.O.P.E 分支深处时,要不惜一切代码锋纤避免使用正则表达式。还要小心各种使用到正则表达式的JDK字符串方法,比如 String.replaceAll() 或 String.split()。可以选择用比较流行的埋丛开发库,比如 Apache Commons Lang 来进行字符串操作。
㈤ java如何实现txt下载 就是从远程FTP服务器上直接把TXT文本下载下来!
strUrl为文件地址,fileName为文件在本地的保存路径,试试吧~
public static void writeFile(String strUrl, String fileName) {
URL url = null;
try {
url = new URL(strUrl);
} catch (MalformedURLException e2) {
e2.printStackTrace();
}
InputStream is = null;
try {
is = url.openStream();
} catch (IOException e1) {
e1.printStackTrace();
}
OutputStream os = null;
try {
os = new FileOutputStream( fileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
System.out.println("下载成功:"+strUrl);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
㈥ java FTP下载文件在代码中如何实现知道下载完成
(KmConfigkmConfig,StringfileName,StringclientFileName,OutputStreamoutputStream){
try{
StringftpHost=kmConfig.getFtpHost();
intport=kmConfig.getFtpPort();
StringuserName=kmConfig.getFtpUser();
StringpassWord=kmConfig.getFtpPassword();
Stringpath=kmConfig.getFtpPath();
FtpClientftpClient=newFtpClient(ftpHost,port);//ftpHost为FTP服务器的IP地址,port为FTP服务器的登陆端口,ftpHost为String型,port为int型。
ftpClient.login(userName,passWord);//userName、passWord分别为FTP服务器的登陆用户名和密码
ftpClient.binary();
ftpClient.cd(path);//path为FTP服务器上保存上传文件的路径。
try{
TelnetInputStreamin=ftpClient.get(fileName);
byte[]bytes=newbyte[1024];
intcnt=0;
while((cnt=in.read(bytes,0,bytes.length))!=-1){
outputStream.write(bytes,0,cnt);
}
//##############################################
//这里文件就已经下载完了,自己理解一下
//#############################################
outputStream.close();
in.close();
}catch(Exceptione){
ftpClient.closeServer();
e.printStackTrace();
}
ftpClient.closeServer();
}catch(Exceptione){
System.out.println("下载文件失败!请检查系统FTP设置,并确认FTP服务启动");
}
}
㈦ java ftp批量下载异常
我之前也遇到过这样的事,通过FTP获取文件的二进制流有限制,获取第二个流的时候需要断掉链接后再重新连接服务器读取流
㈧ java FTP下载
检查一下是否timeout时间设置过短。不要设置内存或者处理器限制。 还有在IIS的metabase数据库中找一下FTP的设置,在那里找配置文件修改最直接。
通过CFtpFileFind 得到文件的URL之后,然后通过CHttpFile::QueryInfo 得到文件大小。
求采纳为满意回答。
㈨ java ftp上批量下载。。。如何和本地文件对应比较。。
比较文件名、比较文件大小,或者比较文件字节序列。最绝的方法是比较文件的MD5值!
㈩ 请教Java Jsp中Ftp文件下载问题
<%@ page contentType="text/html; charset=GBK"%>
<%@ page language="java" import="java.io.IOException" pageEncoding="GBK"%>
<%@ page import="com.enterprisedt.net.ftp.FTPClient"%>
<%@ page import="com.enterprisedt.net.ftp.FTPTransferType"%>
<%@ page import="java.io.*,com.enterprisedt.net.ftp.FTPConnectMode;"%>
<html>
<head>
<title>主页面</title>
</head>
<body>
<%
String path = null;
String filename = null;
path = request.getParameter("path");
filename = request.getParameter("filename");
//response.setContentType("application/unknown");//设置为下载application/x-download
//其中%20是空格在UTF-8下的编码
//filename = URLEncoder.encode(filename, "UTF-8");
//filename = new String(filename.getBytes("gb2312"),"ISO8859-1");
//response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\";");
String host = "192.168.12.49";
String users = "admin";
String passwords = "admin";
if (path.trim().length() > 1) {
path = path.trim() + "/";
}
String remoteFile = path + filename; //确定源文件的位置
String downFile = "d:/" + filename; //确定源文件的位置
System.out.println(remoteFile + " 正在下载中,请稍等................");
try {
OutputStream outputStream = response.getOutputStream();
FTPClient client = new FTPClient();
client.setRemoteHost(host);
//client.setDetectTransferMode(true);
client.connect();
client.login(users, passwords);
client.setConnectMode(FTPConnectMode.ACTIVE);
client.setType(FTPTransferType.BINARY);
//client.get(outputStream, remoteFile); //*方式一:将ftp上的文件取出后,写入到response(outputStream),以response把文件带到浏览器,由浏览器来提示用户是否愿意保存文件到本
//*一直存在中文文件名没有解决的问题
client.get(downFile, remoteFile); //*方式二:将FTP上文件取出后,直接下载到D盘下
outputStream.close();
client.quit();
} catch (IOException e) {
e.printStackTrace();
}
%>
</body>
</html>