javaftpapache
‘壹’ java如何设置apache ftpserver api 的数据端口
ftpd.bat ftpd-typical.xml
‘贰’ java Apache ftp下载文件内容乱码,不是文件名乱码,设置了[ftp.setControlEncoding("GBK");]也没用。
我估计是你的第二张图的那个文件的保存的编码格式跟你设置的GBK的传输编码格式不一致
‘叁’ java ftp 有哪些工具类
java ftp 最常用的是apache commons-net
commons-net项目中封装了各种网络协议的客户端,支持的协议包括:
FTP
NNTP
SMTP
POP3
Telnet
TFTP
Finger
Whois
rexec/rcmd/rlogin
Time (rdate) and Daytime
Echo
Discard
NTP/SNTP
其他的还有FTP4J ,jftp
‘肆’ java FTP下载
检查一下是否timeout时间设置过短。不要设置内存或者处理器限制。 还有在IIS的metabase数据库中找一下FTP的设置,在那里找配置文件修改最直接。
通过CFtpFileFind 得到文件的URL之后,然后通过CHttpFile::QueryInfo 得到文件大小。
求采纳为满意回答。
‘伍’ java中怎么实现ftp文件传输
packagecom.quantongfu.ftp.ftp;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.net.ServerSocket;
importjava.util.List;
importorg.apache.commons.net.ftp.FTPReply;
importorg.apache.log4j.Logger;
importorg.apache.log4j.net.SocketServer;
importcom.quantongfu.conf.FtpConf;
/**
*@项目名称:telinSyslog
*@文件名称:Ftp.java
*@创建日期:2015年9月14日下午3:22:08
*@功能描述:ftp实体类,用于连接,上传
*@修订记录:
*/
publicclassFtp{
privatestaticLoggerlogger=Logger.getLogger(Ftp.class);
privateFTPClientftp;
/**
*
*@parampath
*上传到ftp服务器哪个路径下
*@paramaddr
*地址
*@paramport
*端口号
*@paramusername
*用户名
*@parampassword
*密码
*@return
*@throwsException
*/
publicbooleanconnect()throwsException{
booleanresult=false;
ftp=newFTPClient();
intreply;
ftp.connect(FtpConf.FTP_HOST,FtpConf.FTP_PORT);
ftp.login(FtpConf.FTP_USER_NAME,FtpConf.FTP_PASSWORD);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
ftp.setDataTimeout(60000);
reply=ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
ftp.disconnect();
returnresult;
}
if(FtpConf.IS_FTP_DIRECTORY){
ftp.changeWorkingDirectory(FtpConf.FTP_DIRECTORY);
}
result=true;
returnresult;
}
/**
*
*@paramfiles
*上传的文件
*@throwsException
*/
publicbooleanupload(Filefile)throwsIOException{
FileInputStreaminput=null;
try{
input=newFileInputStream(file);
booleanb=ftp.storeFile(file.getName()+".tmp",input);
if(b){
b=ftp.rename(file.getName()+".tmp",file.getName());
}
returnb;
}catch(Exceptione){
e.printStackTrace();
returnfalse;
}finally{
if(input!=null){
input.close();
}
}
}
/**
*
*@paramfiles
*上传的文件
*@throwsException
*/
publicbooleanupload(ServerSocketserver,Filefile)throwsException{
FileInputStreaminput=null;
try{
if(!file.exists()){
returntrue;
}
input=newFileInputStream(file);
booleanb=ftp.storeFile(server,file.getName()+".tmp",input);
if(b){
b=ftp.rename(file.getName()+".tmp",file.getName());
if(b){
file.delete();
}
}
returnb;
}catch(Exceptione){
logger.error("ftperror"+e.getMessage());
returnfalse;
}finally{
if(input!=null){
try{
input.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}
}
/*断开连接*/
publicvoiddisConnect(){
try{
if(ftp!=null){
ftp.disconnect();
}
}catch(IOExceptione){
e.printStackTrace();
}
}
/*获取连接*/
publicstaticFtpgetFtp(){
Ftpftp=newFtp();
try{
ftp.connect();
}catch(Exceptione){
logger.error("FTP连接异常"+e.getMessage());
e.printStackTrace();
}
returnftp;
}
/*重连*/
publicFtpreconnect(){
disConnect();
returngetFtp();
}
}
使用Apache FtpClient jar包,获取jar : http://commons.apache.org/net/
‘陆’ 如何用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);
}
}
}