当前位置:首页 » 文件管理 » javaapacheftp

javaapacheftp

发布时间: 2022-02-25 01:28:39

A. 如何用java实现ftp服务器

1.使用的FileZillaServer开源免费软件,安装过后建立的本地FTP服务器。2.使用的apache上下载FTP工具包,引用到工程目录中。3.IDE,Eclipse,JDK6上传和下载目录的实现原理:对每一个层级的目录进行判断,是为目录类型、还是文件类型。如果为目录类型,采用递归调用方法,检查到最底层的目录为止结束。如果为文件类型,则调用上传或者下载方法对文件进行上传或者下载操作。贴出代码:(其中有些没有代码,可以看看,还是很有用处的)!

B. java apache FTPClient上传文件时的一个问题

源文件不变 长传时候在文件后面加.tmp 或者你想的后缀 完成后 操作这个文件重命名 具体代码懒得贴了

C. java 用代码怎么去调用windows 的ftp 服务器下传下载

ftp不分windows还是linux,走的是协议,apache有开源的ftp上传下载实现,下载就可以了
在net包里面

D. java Apache ftp下载文件内容乱码,不是文件名乱码,设置了[ftp.setControlEncoding("GBK");]也没用。

我估计是你的第二张图的那个文件的保存的编码格式跟你设置的GBK的传输编码格式不一致

E. 如何用java 程序启动Apache-ftpserver 功能

public class FtpServerListener implements ServletContextListener {

public static final String FTPSERVER_CONTEXT_NAME = "org.apache.ftpserver";

public void contextDestroyed(ServletContextEvent sce) {
System.out.println("Stopping FtpServer");

FtpServer server = (FtpServer) sce.getServletContext().getAttribute(FTPSERVER_CONTEXT_NAME);

if(server != null) {
server.stop();

sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);

System.out.println("FtpServer stopped");
} else {
System.out.println("No running FtpServer found");
}

}

public void contextInitialized(ServletContextEvent sce) {
System.out.println("Starting FtpServer");

WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());

FtpServer server = (FtpServer) ctx.getBean("myFtpServer");

sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);

try {
server.start();
System.out.println("FtpServer started");
} catch (Exception e) {
throw new RuntimeException("Failed to start FtpServer", e);
}
}

}

F. java做ftp服务器需要什么jar包

apache的包:commons-net.jar
主要使用到的类:
org.apache.commons.net.ftp.FTPClient;
org.apache.commons.net.ftp.FTPFile;
org.apache.commons.net.ftp.FTPReply;

JDK中也有自带的ftp包:
sun.net.ftp.下有FTP操作类
但sun已经不建议使用了, 建议楼主使用apache的包

G. java怎么在ftp上取到文件夹中文件再录入txt文本

前段时间正好看了这个。

http://www.codejava.net/java-se/networking/ftp/java-ftp-file-download-tutorial-and-example

这个文档非常好。有什么看不懂的再问吧。

主要是使用org.apache.commons.net.ftp.FTPClient 和org.apache.commons.net.ftp.FTP 类。

核心代码:

ftpClient.connect(server,port);
ftpClient.login(user,pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

//APPROACH#1:usingretrieveFile(String,OutputStream)
StringremoteFile1="/test/video.mp4";
FiledownloadFile1=newFile("D:/Downloads/video.mp4");
OutputStreamoutputStream1=newBufferedOutputStream(newFileOutputStream(downloadFile1));
booleansuccess=ftpClient.retrieveFile(remoteFile1,outputStream1);
outputStream1.close();

if(success){
System.out.println("File#.");
}

H. java如何设置apache ftpserver api 的数据端口


ftpd.bat ftpd-typical.xml

I. 如何用java连接到ftp上

现在已经封装好了的方法,不需要任何其他知识即可连接的。只需要知道ftp登录用户名、密码、端口、存储路径即可。
package zn.ccfccb.util;

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);
// Log.info("连接远程上传服务器"+"192.168.54.106:"+2021);
// ftpClient.connect("192.168.54.106", 2021);
// ftpClient.login("hkrt-CCFCCBHK", "3OLJheziiKnkVcu7Sigz");
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);
// ftpClient.connect(CMBCUtil.CMBCHOSTNAME, 2021);
// ftpClient.login(CMBCUtil.CMBCLOGINNAME, 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);
}

热点内容
eds服务器是什么 发布:2024-10-27 16:02:39 浏览:1
mysqlpython连接池 发布:2024-10-27 16:02:35 浏览:180
四川阿里云服务器选哪里 发布:2024-10-27 15:55:18 浏览:700
soaphp 发布:2024-10-27 15:54:21 浏览:218
我的世界暑期红石服务器 发布:2024-10-27 15:54:11 浏览:958
台湾ip代理服务器云服务器 发布:2024-10-27 15:53:21 浏览:645
app编译原理 发布:2024-10-27 15:52:20 浏览:105
qq留言的访问记录 发布:2024-10-27 15:49:41 浏览:877
androidtextview点击事件 发布:2024-10-27 15:42:24 浏览:692
安卓全民k歌怎么唱 发布:2024-10-27 15:23:51 浏览:964