当前位置:首页 » 文件管理 » ftp下载java

ftp下载java

发布时间: 2022-08-23 13:21:37

java 下载异地ftp中的zip文件

好像需要一个支持jar包把,把ftp4j的下载地址贴出来

㈡ 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下载,求解list<Object>问题

我觉的是传来的list为null,所以会空指针异常,你的先判断
if(list!=null){
for (int i = 0; i < list.size() ; i++) {
Object[] os = list.get(i);
String fileName = (String) os[0];
String relPath = (String) os[1];
String midPath = "/data/edocs/WORKING/NORMAL";
String remotePath = strFtp + midPath + relPath; // FTP上要下载的文 件路径,不包括文件名
ftp.downFile(remotePath, fileName, savePath);
}

}

㈣ java FTP下载问题

检查一下是否timeout时间设置过短。不要设置内存或者处理器限制。 还有在IIS的metabase数据库中找一下FTP的设置,在那里找配置文件修改最直接。
通过CFtpFileFind 得到文件的URL之后,然后通过CHttpFile::QueryInfo 得到文件大小。

㈤ 用java完成文件ftp上传下载

使用rt.jar中的sun.net.FtpClient类来实现对FTP服务器的文件上传下载

㈥ java ftp批量下载异常

我之前也遇到过这样的事,通过FTP获取文件的二进制流有限制,获取第二个流的时候需要断掉链接后再重新连接服务器读取流

㈦ java FTP下载

检查一下是否timeout时间设置过短。不要设置内存或者处理器限制。 还有在IIS的metabase数据库中找一下FTP的设置,在那里找配置文件修改最直接。
通过CFtpFileFind 得到文件的URL之后,然后通过CHttpFile::QueryInfo 得到文件大小。
求采纳为满意回答。

㈧ ftp java 下载的时候怎么保存到指定位置

通过工具类来实现本地路径定义和下载即可。

import hkrt.b2b.view.util.Log;
import hkrt.b2b.view.util.ViewUtil;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;

public class CCFCCBFTP {

/**
* 上传文件
*
* @param fileName
* @param plainFilePath 明文文件路径路径
* @param filepath
* @return
* @throws Exception
*/
public static String fileUploadByFtp(String plainFilePath, String fileName, String filepath) throws Exception {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
FTPClient ftpClient = new FTPClient();
String bl = "false";
try {
fis = new FileInputStream(plainFilePath);
bos = new ByteArrayOutputStream(fis.available());
byte[] buffer = new byte[1024];
int count = 0;
while ((count = fis.read(buffer)) != -1) {
bos.write(buffer, 0, count);
}
bos.flush();
Log.info("加密上传文件开始");
Log.info("连接远程上传服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);
ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);
ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);
FTPFile[] fs;
fs = ftpClient.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(filepath)) {
bl="true";
ftpClient.changeWorkingDirectory("/"+filepath+"");
}
}
Log.info("检查文件路径是否存在:/"+filepath);
if("false".equals(bl)){
ViewUtil.dataSEErrorPerformedCommon( "查询文件路径不存在:"+"/"+filepath);
return bl;
}
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
// 设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile(fileName, fis);
Log.info("上传文件成功:"+fileName+"。文件保存路径:"+"/"+filepath+"/");
return bl;
} catch (Exception e) {
throw e;
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
if (bos != null) {
try {
bos.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
}

}

/**
*下载并解压文件
*
* @param localFilePath
* @param fileName
* @param routeFilepath
* @return
* @throws Exception
*/
public static String fileDownloadByFtp(String localFilePath, String fileName,String routeFilepath) throws Exception {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
FileOutputStream fos = null;
FTPClient ftpClient = new FTPClient();
String SFP = System.getProperty("file.separator");
String bl = "false";
try {
Log.info("下载并解密文件开始");
Log.info("连接远程下载服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);
ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);
ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);
CMBCUtil.CMBCLOGINPASSWORD);

FTPFile[] fs;

ftpClient.makeDirectory(routeFilepath);
ftpClient.changeWorkingDirectory(routeFilepath);
bl = "false";
fs = ftpClient.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(fileName)) {
bl = "true";
Log.info("下载文件开始。");
ftpClient.setBufferSize(1024);
// 设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
InputStream is = ftpClient.retrieveFileStream(fileName);
bos = new ByteArrayOutputStream(is.available());
byte[] buffer = new byte[1024];
int count = 0;
while ((count = is.read(buffer)) != -1) {
bos.write(buffer, 0, count);
}
bos.flush();
fos = new FileOutputStream(localFilePath+SFP+fileName);
fos.write(bos.toByteArray());
Log.info("下载文件结束:"+localFilePath);
}
}
Log.info("检查文件是否存:"+fileName+" "+bl);
if("false".equals(bl)){
ViewUtil.dataSEErrorPerformedCommon("查询无结果,请稍后再查询。");
return bl;
}
return bl;
} catch (Exception e) {
throw e;
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
if (bos != null) {
try {
bos.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
}
}

// 调用样例:
public static void main(String[] args) {
try {

// 明文文件路径
String plainFilePath = "D:/req_20150204_0011.txt";
// 密文文件路径
String secretFilePath = "req_20150204_00134.txt";
fileDownloadByFtp("D://123.zip","123.zip","req/20150228");
} catch (Exception e) {
e.printStackTrace();
}
}

}

㈨ 用java实现ftp下载,路径的问题,很晕

ftpClient.changeWorkingDirectory(”20110814“),你应该这么写,如果用/开头表示是绝对路径,而 20110814表示是相对路径,你看下绝对路径跟相对路径就明白了

热点内容
如何寻找资产配置机会 发布:2024-10-13 19:13:47 浏览:373
轿车安卓中控怎么安装手机卡 发布:2024-10-13 19:05:23 浏览:448
商城首页android 发布:2024-10-13 17:53:20 浏览:496
甲骨文云服务器如何申请 发布:2024-10-13 16:49:39 浏览:134
c语言中参数传递 发布:2024-10-13 16:30:15 浏览:81
cos服务器搭建 发布:2024-10-13 16:17:41 浏览:335
象棋软件算法 发布:2024-10-13 15:32:35 浏览:901
平板怎么看真正配置 发布:2024-10-13 14:53:32 浏览:35
微信存储空间的其他 发布:2024-10-13 14:52:14 浏览:672
怎么绕过系统密码登录密码登录密码登录 发布:2024-10-13 14:47:41 浏览:510