`
- 浏览:
40482 次
- 性别:
- 来自:
深圳
-
采用 apache的 commons-net包
java 代码
- import java.io.FileInputStream;
- import java.io.IOException;
-
- import org.apache.commons.net.ftp.FTP;
- import org.apache.commons.net.ftp.FTPClient;
- import org.apache.commons.net.ftp.FTPReply;
- import org.apache.log4j.Logger;
-
- public class FtpUtil {
- private Logger log = Logger.getLogger(this.getClass());
- private String ftpServer;
- private String userName;
- private String pswd;
-
- public void setFtpServer(String ftpServer) {
- this.ftpServer = ftpServer;
- }
-
- public void setPswd(String pswd) {
- this.pswd = pswd;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
-
-
-
-
-
- public FTPClient loginToFtpServer() throws Exception {
-
- FTPClient ftp = new FTPClient();
- try {
- ftp.connect(this.ftpServer);
- int reply = ftp.getReplyCode();
- if(!FTPReply.isPositiveCompletion(reply)){
- log.error("Ftp connect to "+this.ftpServer +" failed!");
- throw new Exception("Ftplogin to connect to "+this.ftpServer +" failed!");
- }
- ftp.login(this.userName,this.pswd);
- log.debug("Ftp connect to "+this.ftpServer +" success!");
-
- } catch (Exception e) {
- log.error("Ftp connect "+this.ftpServer +" failed!!");
- throw new Exception("FtpLogin to "+this.ftpServer +" failed!!");
- }
- return ftp;
- }
-
-
-
-
-
-
-
-
- public void upload(String remotPath,String localFile,String remoteFileName) throws Exception{
- FTPClient ftp = this.loginToFtpServer();
- FileInputStream in = null;
- try {
- log.debug("--- ftp begin! ---");
- ftp.setFileType(FTP.BINARY_FILE_TYPE);
- ftp.enterLocalPassiveMode();
- if(null!=remotPath&&(!ftp.changeWorkingDirectory(remotPath))){
- ftp.makeDirectory( remotPath );
- ftp.changeWorkingDirectory( remotPath );
- }
-
- in = new FileInputStream(localFile);
- ftp.storeFile(remoteFileName, in);
- log.debug("--- ftp finish! ---");
- } catch (IOException e) {
- log.error("ftp file:"+ localFile +" fail!!!");
- throw new Exception("ftp file:"+ localFile +" fail!!!");
- }finally{
- try {
- ftp.disconnect();
- if(null!=in){
- in.close();
- }
- } catch (IOException e) {
- this.log.error("close connect failed!");
- e.printStackTrace();
- }
- }
- }
-
-
-
-
-
-
-
- protected String enCodingRemoteFilePath(String remoteFilePath) {
- return null;
- }
-
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
java FTP 实现上传 下载 拷贝 亲测可用 java FTP 实现上传 下载 拷贝 java FTP 实现上传 下载 拷贝
javaftp实现上传下载解决编码问题
Qt5.8用ftp实现上传和下载文件,并带进度条显示
使用FTP实现文件上传下载。服务器使用的serv-u作为远端。
自己重新封装的C# FTP实现上传,下载,创建文件,文件夹,删除单个文件 MD5校验等, 支持FTP非空目录递归删除操作,测试通过,好用 环境为VS2012 开发
VB代码利用FTP实现文件上传于下载代码 VB代码利用FTP实现文件上传于下载代码
这是Ubuntu16.04环境下自己用C实现的简单的ftp服务功能,只涉及登录、上传、下载、退出功能。服务器端采用epoll多线程机制,可以实现多个客户端的同时接入。简单来说就是仿生FTP。
curl实现ftp上传下载,vs版本实现,可以使用
一款由java实现ftp自动上传整个磁盘所有文件,包括目录,下面的JTextArea读取Log4j及命令行的信息,采用第三方ftpClient.不过下载的部分还没有时间去做.
Qt+libcurl实现FTP文件上传和下载Qt+libcurl实现FTP文件上传和下载
可以实现文件上传功能,并能检索到FTP目前的目录
java实现的ftp文件上传
用C#语言来实现FTP上传、下载功能。还支持同步异步来操作。简单实用
可以实现ftp上传图片文件到指定ftp目录php实现通过ftp上传图片文件,用户无需手动更改目录,上传时可以选择是否上传到ftp位置,可有本地跟ftp可选
FtpWebRequest类实现FTP客户端的开发,C#开发,可实现获取服务器文件资源列表并显示出来,可进行文件的上传和下载。
易语言API实现FTP上传源码
FTP 客户端实现 1.单文件上传 2.多文件上传 3.加密文件 4.下载文件 5.解密文件 6.文件冲突 7.文件夹上传
NULL 博文链接:https://weareold.iteye.com/blog/638019
c# 实现文件FTP上传至服务器 WebClient上传文件至服务器(不带进度条) 要上传的文件(全路径格式) <param name="strUrlDirPath">Web服务器文件夹路径 <returns>True/False是否上传成功</returns>