- 浏览: 495295 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (285)
- 数据库 (49)
- dwr (1)
- js (35)
- security (6)
- freemaker (4)
- 网站建设 (15)
- css (5)
- javaEE (56)
- 生活点滴 (12)
- 安装与配置 (16)
- ssh2 (13)
- 开源软件 (6)
- web 应用服务器 (6)
- 开发模式和设计模式 (2)
- linux (5)
- 项目管理 (7)
- 计算机杂症 (0)
- appScan (1)
- idea (3)
- android (1)
- java @override 报错处理 (1)
- lucene (5)
- java (2)
- groovy (1)
- Extjs (7)
- asp (2)
- php (2)
- Memcached (1)
- 名言 (1)
- 面试 (1)
- Jmeter (0)
- 微信支付 (1)
- app开发 (1)
- branch分支合并到trunk主干 (1)
- 自动化测试 (1)
- springClond (1)
- ELK (2)
最新评论
-
skykufo:
坑爹啊,我也因为写多了一个div,在ie8浪费了一天
jQuery加载(load、get、post)页面显示空白原因 -
yeyinzhu3211:
帅哥,我想问下,是怎么去除呀?能详细说明下吗?
IntelliJ IDEA 10.5.1 无法断点或停止不动 -
sshitaime:
怎么下载不了啊,能给我一个安装包吗
oracle 10g透明网关组件下载地址(新) -
fuanyu:
xiaohuafyle 写道被你的头像吓尿了 哥们有这么可怕呀 ...
netstat -aon -
wanlt_software:
谢谢。。。。。
oracle 10g透明网关组件下载地址(新)
本文来自:http://cd0281.iteye.com/blog/682103
package download; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import sun.net.TelnetInputStream; import sun.net.TelnetOutputStream; import sun.net.ftp.FtpClient; public class Download { String localfilename; String remotefilename; FtpClient ftpClient; // server:服务器名字 // user:用户名 // password:密码 // path:服务器上的路径 public void connectServer(String ip, int port, String user, String password, String path) { try { ftpClient = new FtpClient(); ftpClient.openServer(ip, port); ftpClient.login(user, password); System.out.println("login success!"); if (path.length() != 0) ftpClient.cd(path); ftpClient.binary(); } catch (IOException ex) { System.out.println("not login"); System.out.println(ex); } } public void closeConnect() { try { ftpClient.closeServer(); System.out.println("disconnect success"); } catch (IOException ex) { System.out.println("not disconnect"); System.out.println(ex); } } public void upload() { this.localfilename = "D://test2//test.txt"; this.remotefilename = "test.txt"; try { TelnetOutputStream os = ftpClient.put(this.remotefilename); java.io.File file_in = new java.io.File(this.localfilename); FileInputStream is = new FileInputStream(file_in); byte[] bytes = new byte[1024]; int c; while ((c = is.read(bytes)) != -1) { os.write(bytes, 0, c); } System.out.println("upload success"); is.close(); os.close(); } catch (IOException ex) { System.out.println("not upload"); System.out.println(ex); } } public void download() { try { TelnetInputStream is = ftpClient.get(this.remotefilename); java.io.File file_in = new java.io.File(this.localfilename); FileOutputStream os = new FileOutputStream(file_in); byte[] bytes = new byte[1024]; int c; while ((c = is.read(bytes)) != -1) { // System.out.println((char)is.read()); // System.out.println(file_in); os.write(bytes, 0, c); } System.out.println("download success"); os.close(); is.close(); } catch (IOException ex) { System.out.println("not download"); System.out.println(ex); } } public void download(String remotePath, String remoteFile, String localFile) { try { if (remotePath.length() != 0) ftpClient.cd(remotePath); TelnetInputStream is = ftpClient.get(remoteFile); java.io.File file_in = new java.io.File(localFile); FileOutputStream os = new FileOutputStream(file_in); byte[] bytes = new byte[1024]; int c; while ((c = is.read(bytes)) != -1) { // System.out.println((char)is.read()); // System.out.println(file_in); os.write(bytes, 0, c); } System.out.println("download success"); os.close(); is.close(); } catch (IOException ex) { System.out.println("not download"); System.out.println(ex); } } public void download(String remoteFile, String localFile) { try { TelnetInputStream is = ftpClient.get(remoteFile); java.io.File file_in = new java.io.File(localFile); FileOutputStream os = new FileOutputStream(file_in); byte[] bytes = new byte[1024]; int c; while ((c = is.read(bytes)) != -1) { // System.out.println((char)is.read()); // System.out.println(file_in); os.write(bytes, 0, c); } System.out.println("download success"); os.close(); is.close(); } catch (IOException ex) { System.out.println("not download"); System.out.println(ex); } } public static void main(String agrs[]) { String filepath[] = { "/callcenter/index.jsp", "/callcenter/ip.txt", "/callcenter/mainframe/image/processing_bar_2.gif", "/callcenter/mainframe/image/logo_01.jpg" }; String localfilepath[] = { "C:\\FTP_Test\\index.jsp", "C:\\FTP_Test\\ip.txt", "C:\\FTP_Test\\processing_bar_2.gif", "C:\\FTP_Test\\logo_01.jpg" }; Download fu = new Download(); fu.connectServer("172.16.1.66", 22, "web_test", "123456", "/callcenter"); for (int i = 0; i < filepath.length; i++) { fu.download(filepath[i], localfilepath[i]); } // fu.upload(); // fu.download(); fu.closeConnect(); } }
另一篇:http://vipjustin.blog.163.com/blog/static/19966227200732734834722/
发表评论
-
java 模拟微信浏览器http请求
2020-12-16 08:49 720public static void main(St ... -
java 小数点处理的问题
2015-08-22 16:23 747float num= (float)1/100 ... -
java操作excel 替换指定字符串
2014-12-26 10:27 5220根据excel模板里设置指定的num0,num1,num2 ... -
itext对水印图片的旋转、放大、缩小等操作的示例
2014-07-24 17:17 5731package test1; import java. ... -
java 获取ip
2014-04-25 16:38 828public static String getIpAddr ... -
读取poi
2014-03-12 17:57 1303/** * Writer: fuanyu * Dat ... -
对Map排序
2014-02-20 15:38 758本来来自:http://blog.sina.com.cn/s ... -
java 上下篇文章实现的思路
2014-02-14 15:03 755当前文章的ID =request("id" ... -
Java:String和Date、Timestamp之间的转换
2013-12-03 14:39 10211.1 String -> Date String ... -
ArrayList和数组间的相互转换
2012-07-31 16:00 1082package test.test1; import ... -
No result defined for action and result
2012-07-02 11:50 973当你在用struts2开发时,如果,从页面跳入action时, ... -
IntelliJ IDEA 10.0 使用javac 编译程序出现“非法字符: \65279 ”解决方法
2012-04-26 11:42 2144一、问题描述: 将在eclipse 创建的项目代码导入 I ... -
map取key及key的值
2012-03-19 15:53 1602public class Test2 { p ... -
用jdbc操作CLOB型数据的两种方式
2012-02-08 10:29 1275最近学Oracle,正好单位OA中Word文件是将文件用BAS ... -
java @override 报错处理
2012-02-02 14:14 1315有时候在自己电脑上编译通过的java代码,在别人那里确编译 ... -
Java判断字符串中是否包含汉字
2011-12-15 11:54 2257有两个方法 import java.util.regex.M ... -
JMagick+ImageMagic处理图片(高质量)
2011-11-27 13:37 2661项目需要简单处理一些用户上传的图片,如缩略图、剪切、旋转、水印 ... -
定时发送邮件的思路
2011-11-19 12:11 1270定时发送邮件:大概是用户选择在某个时间发送邮件; 步骤: ... -
java 解析json
2011-11-10 17:00 1099如下面代码 String str="[{'bus ... -
javamail 收邮件遇到的问题及解决方法
2011-11-04 16:29 22681.java.io.UnsupportedEncodingEx ...
相关推荐
java实现ftp上传和下载文件功能 文档里有详细的代码
java中实现ftp下载功能,支持断点下载
Java实现FTP的上传下载功能
java实现ftp功能 上传功能
用Java实现FTP批量大文件上传下载(一) 本文介绍了在Java中,如何使用Java现有的可用的库来编写FTP客户端代码,并开发成Applet控件,做成基于Web的批量、大文件的上传下载控件。文章在比较了一系列FTP客户库的基础上...
山东大学计算机网络课程设计,利用Java实现类似于FTP的相关功能,用户登录,用户上传文件,下载文件,删除文件。使用Javasocket的作为传输底层。
这是我使用java实现的linux和ftp服务器文件上传下载工具,需要电脑安装jdk8, 启动命令,java -jar linuxAndFtp.jar 启动成功后,浏览器访问:http://localhost:9999 服务器的账号密码通过服务器列表页面管理,添加的...
使用java实现的操作ftp等一系列功能,比较完整,全面。放心下载
java实现文件上传到FTP和从FTP下载到本地功能,里面没有jar架包,但有说明要哪些架包
如何在Java程序中实现FTP的上传下载功能.txt FtpList部分是用来显示FTP服务器上的文件; GetButton部分为从FTP服务器下传一个文件; PutButton部分为向FTP服务器上传一个文件 ………………………………...
利用java进行ftp上传文件,通过java代码实现ftp上传文件的功能。
在JAVA的编程中,您也许会遇到FTP方面的编程,本文就来演示如何实现它。本程序是由JBUILDER2.0来开发的, FtpList 部分是用来显示FTP服务器上的文件(附图略)。GetButton部分为从FTP服务器下传一个文件。PutButton...
在JAVA的编程中,也许会遇到FTP方面的编程,本文就来演示如何实现它。本程序是由JBUILDER2.0来开发的,为了节约篇幅我只列出主要的三个部份。FtpList 部分是用来显示FTP服务器上的文件(附图略)。GetButton部分为从...
看了很多别人写的java连接ftp服务器的上传和下载,都没有能够实现的需要的功能。自己写了一个连接ftp服务器,并实现定时上传和下载。已经实现,正在使用,很好用的。
本文介绍了在Java中,如何使用Java现有的可用的库来编写FTP客户端代码,并开发成Applet控件,做成基于Web的批量、大文件的上传下载控件。文章在比较了一系列FTP客户库的基础上,就其中一个比较通用且功能较强的j-ftp...
java 连接linux系统上的ftp服务器,通过java代码上传,下载文件 通过链接ftp,获取文件列表,上传。下载、删除文件功能实现
一款JAVA手机上连接FTP的软件;很适合手机党建站的需求;此程序具有很多功能;能上传和在线编辑源码文件
使用Apache commons net组件实现ftp上传与下载功能