A. FTPClient 是什么
FTP客户端
B. filezilla ftp client和filezilla server有什么区别分别有什么用途
前者是客户端,用来通过ftp或者sftp协议上传下载文件的 ------ 有它,你能连别人的服务器上传和下载
后者是服务端,用来搭建ftp或者sftp服务的(以便为别人通过ftp客户端访问自己的文件提供服务) ----有它,别人能连你的服务器上传下载。
========================
什么情况啊,一直提示完善回答,这个回答够完善啦。
C. Java类库中FtpClient的ftpClient用法是什么
切换工作路径啊,
ftpClient.changeWorkingDirectory("/admin/pic"); //工作路径切换到/admin/pic ,ftpClient.setBufferSize(1024); //设置1M缓冲,
ftpClient.setControlEncoding("GBK"); //设置编码为GBK,
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); //文件类型为二进制文件,
ftpClient.storeFile("3.gif", fis)//在前面设置好路径,缓冲,编码,文件类型后,开始上传3.gif。
D. ftpsclient 和ftpclient有什么区别
FTP(FileTransferProtocol)是Internet上用来传送文件的协议(文件传输协议)。它是为了我们能够在Internet上互相传送文件而制定的的文件传送标准,规定了Internet上文件如何传送。也就是说,通过FTP协议,我们就可以跟Internet上的FTP服务器进行文件的上传(Upload)或下载(Download)等动作。WWW的核心——HTTP协议众所周知,Internet的基本协议是TCP/IP协议,目前广泛采用的FTP、ArchieGopher等是建立在TCP/IP协议之上的应用层协议,不同的协议对应着不同的应用。WWW服务器使用的主要协议是HTTP协议,即超文体传输协议。由于HTTP协议支持的服务不限于WWW,还可以是其它服务,因而HTTP协议允许用户在统一的界面下,采用不同的协议访问不同的服务,如FTP、Archie、SMTP、NNTP等。另外,HTTP协议还可用于名字服务器和分布式对象管理。
E. FtpClient这个类的方法怎么用
jdk1.7下其构造函数FtpClient()被定义为private类型,所以无法new了。 在jdk1.7,已经换成了 FtpClient.create(ip)方法.
同时,其他的一些方法也基本都改掉了,
如 ftpClient.openServer(server);
ftpClient.login(user, password);
就可以换成:ftpClient.login(user, null, password);
ftpClient.binary(); ---> ftpClient.setBinaryType();
ftpClient.put(remotefilename);--->ftpClient.putFileStream(remotefilename, true);
等。
F. FtpClient
当时我用SUN 的FtpClient.get()方法下载文件是有问题的,我推荐你用org.apache.commons.net.ftp.FTPClient下载文件,可以解决中文文件下载问题,你可以去我博客里看看哦:http://hi..com/renliangli/blog/item/6ccb6b3a049d95c9d46225a5.html,文章摘给你吧:
现在就来看下我解决的代码吧,希望对遇到同样问题的人有点帮助。
1)把ftp地址中的文件保存到本地的java类源码:
package test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class Ftp {
/**
* Description: 从FTP服务器下载文件
* @param ip FTP服务器的ip地址
* @param port FTP服务器端口,默认为:21
* @param username FTP登录账号
* @param password FTP登录密码
* @param remotePath FTP服务器上的相对路径
* @param fileName 要下载的文件名
* @param localPath 下载后保存到本地的路径
* @return
*/
public static boolean downFile(String ip, int port,String username, String password, String remotePath,String fileName,String localPath) {
boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(ip, port);
//下面三行代码必须要,而且不能改变编码格式,否则不能正确下载中文文件
ftp.setControlEncoding("GBK");
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
conf.setServerLanguageCode("zh");
//如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
ftp.login(username, password);//登录
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录
FTPFile[] fs = ftp.listFiles();
for(int i = 0; i < fs.length; i++){
FTPFile ff = fs[i];
if(ff.getName().equals(fileName)){
File localFile = new File(localPath+File.separator+ff.getName());
//
OutputStream is = new FileOutputStream(localFile);
//注意此处retrieveFile的第一个参数由GBK转为ISO-8859-1编码。否则下载后的文件内容为空。
//原因可能是由于aix系统默认的编码为ISO-8859-1
ftp.retrieveFile(new String(ff.getName().getBytes("GBK"),"ISO-8859-1"), is);
is.close();
}
}
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Ftp.downFile("10.32.166.144", 21, "test", "test", "/flashfxp", "激活码.txt", "C:");
}
}
2)将ftp资源以文件流的方式打开,由用户决定保存在本地何处,程序运行后可以从IE跳出框中打开或者保存的Action代码,利用Struts1写的:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.mocha.test;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class DownloadAction extends Action{
/** *//**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException{
OutputStream os=null;
try {
os = response.getOutputStream();
response.reset();
downFile("10.32.166.144", 21, "test", "test", "/flashfxp", "激活码.txt",os,response);
} catch (IOException e){
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try{
os.close();
} catch (IOException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
/**
* Description: 从FTP服务器下载文件
* @param ip FTP服务器ip地址
* @param port FTP服务器端口,默认为21
* @param username FTP登录账号
* @param password FTP登录密码
* @param remotePath 附件在FTP服务器上的绝对路径
* @param fileName 要下载的文件名
* @param outputStream 输出流
* @param response
* @return
*/
public static boolean downFile(String ip, int port,String username, String password, String remotePath
,String fileName,OutputStream outputStream,HttpServletResponse response) {
boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(ip, port);
//下面三行代码必须要,而且不能改变编码格式
ftp.setControlEncoding("GBK");
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
conf.setServerLanguageCode("zh");
//如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
ftp.login(username, password);//登录
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录
FTPFile[] fs = ftp.listFiles();
for(int i = 0; i < fs.length; i++){
FTPFile ff = fs[i];
if(ff.getName().equals(fileName)){
String filename = fileName;
//这个就就是弹出下载对话框的关键代码
response.setHeader("Content-disposition",
"attachment;filename=" +
URLEncoder.encode(filename, "utf-8"));
//将文件保存到输出流outputStream中
ftp.retrieveFile(new String(ff.getName().getBytes("GBK"),"ISO-8859-1"), outputStream);
outputStream.flush();
outputStream.close();
}
}
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}
}
差点忘了利用ftpclient要用到的jar包了,呵呵,就这两个了:commons-net-1.4.1.jar、jakarta-oro-2.0.8.jar
对了我用的jdk是1.4的。所以commons-net-1.4.1.jar用了这个版本比较老的。
G. FTPClient需要关闭吗
这是FTP客户端,一般在操作系统中默认开启,不需要关闭
H. ftp client配置是什么意思
FTP客户端配置,设置要连接的FTP服务器的IP,端口,用户名,密码,连接模式等
I. FtpClient.storeFile作用
作用是将流写进服务器。
FTP就是文件传输协议。用于互联网双向传输,控制文件下载空间在服务器复制文件从本地计算机或本地上传文件复制到服务器上的空间。
J. filezilla ftp client和filezilla server有什么区别分别有什么用途
前者是客户端,用来通过ftp或者sftp协议上传写在文件的
------
有它,你能连别人的服务器上传和下载
后者是服务端,用来搭建ftp或者sftp服务的(以便为别人通过ftp客户端访问自己的文件提供服务)
----有他,别人能连你的服务器上传下载