-【Java FTP及FTP服务器搭建】
来源:互联网 发布:灰色西装配马甲 知乎 编辑:程序博客网 时间:2024/06/05 15:20
-【Java FTP及FTP服务器搭建】
一:本文采用apache项目组的
Apache Commons Net™ library
项目地址:http://commons.apache.org/net/
如下图:可见FTP只是其中一个支持的协议,还有很多其他,如有需要的同学,可参考官方网站。
Features
Supported protocols include:
- FTP/FTPS
- FTP over HTTP (experimental)
- NNTP
- SMTP(S)
- POP3(S)
- IMAP(S)
- Telnet
- TFTP
- Finger
- Whois
- rexec/rcmd/rlogin
- Time (rdate) and Daytime
- Echo
- Discard
- NTP/SNTP
二:搭建ftp服务器
1:下载filezilla
http://filezilla-project.org/
如图
2:安装到windows
双击,下一步,完成!
3:启动ftp服务器
双击桌面图标,输入PC的密码
登录成功
4:ftp添加 一个用户,并设置共享文件夹
5:测试
简单的ftp server完成。
三:java代码
FTPClientFTPClient encapsulates all the functionality necessary to store and retrieve files from an FTP server.
上传:
- public class MyFtp {
- public static void main(String[] args) {
- try {
- FTPClient ftp = new FTPClient();
- ftp.connect("127.0.0.1", 21);
- boolean isLogin = ftp.login("a", "a");
- System.out.println("登录:"+isLogin);
- ftp.setFileType(FTP.BINARY_FILE_TYPE);
- boolean isStore = ftp.storeFile("note.txt", new FileInputStream("d:/note.txt"));
- ftp.storeFile("1.png", new FileInputStream("d:/1.png"));
- System.out.println("上传:"+isStore);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
public class MyFtp {public static void main(String[] args) {try {FTPClient ftp = new FTPClient();ftp.connect("127.0.0.1", 21);boolean isLogin = ftp.login("a", "a");System.out.println("登录:"+isLogin);ftp.setFileType(FTP.BINARY_FILE_TYPE);boolean isStore = ftp.storeFile("note.txt", new FileInputStream("d:/note.txt"));ftp.storeFile("1.png", new FileInputStream("d:/1.png"));System.out.println("上传:"+isStore);} catch (Exception e) {e.printStackTrace();}}}
下载:
- public class MyFtp {
- public static void main(String[] args) {
- try {
- FTPClient ftp = new FTPClient();
- ftp.connect("127.0.0.1", 21);
- boolean isLogin = ftp.login("a", "a");
- System.out.println("登录:"+isLogin);
- // ftp.setFileType(FTP.BINARY_FILE_TYPE);
- //
- // boolean isStore = ftp.storeFile("note.txt", new FileInputStream("d:/note.txt"));
- //
- // ftp.storeFile("1.png", new FileInputStream("d:/1.png"));
- //
- // System.out.println("上传:"+isStore);
- boolean isDown = ftp.retrieveFile("note.txt", new FileOutputStream("d:/TDDOWNLOAD/note.txt"));
- isDown = ftp.retrieveFile("1.png", new FileOutputStream("d:/TDDOWNLOAD/note.png"));
- System.out.println("下载:"+isDown);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- -【Java FTP及FTP服务器搭建】
- 菜鸟学堂 -【Java FTP及FTP服务器搭建】
- centos中搭建ftp服务器及配置
- iis搭建ftp服务器及身份验证设置
- Windows server搭建ftp服务器及注意事项
- 什么是FTP及FTP服务器
- 什么是FTP及FTP服务器
- Apache FTPServer Java代码搭建FTP服务器
- 局域网搭建FTP服务器
- centos 搭建 ftp服务器
- Centos 搭建ftp服务器
- win7 搭建ftp服务器
- Ubuntu 搭建FTP服务器
- ftp服务器搭建
- FTP服务器的搭建
- ubuntu ftp服务器搭建
- Windows2003搭建FTP服务器
- Ubuntu 搭建FTP服务器
- sgu 153 Playing with matches
- 动态规划与线性规划
- IO操作 模拟一下BufferedReader和LineNumberReader
- 单词串联记忆 - 故事 - 911三步曲
- BSP 面试总结
- -【Java FTP及FTP服务器搭建】
- win7 64位下使用regsvr32注册QtCored4 dll
- 单词串联记忆 - 故事 - 又一个美丽的故事
- session实现购物
- 俄罗斯方块的构思
- 堆(heap)和栈(stack)、内存泄漏(memory leak)和内存溢出
- 删除字符串中多余的空格(只保留一个空格)
- 游船问题II(DP)
- MyEclipse设置Annotation自动提示