栏目导航
热点推荐
- 巧用DOS命令远程管理FTP服务器
- 菜鸟也能搭建FTP服务器
- CentOS5环境下安装PureFTPd
- 用端口碰撞技术实现服务器远程管
- 教你用SRP服务构建Linux下FTP服
- 用vsftp部署一个功能强大的ftp服
- 在内网IP建FTP服务器
- FTP登陆错误问题完全分析
- FTP资源迅速搬回家
- IIS6.0下建立FTP“用户隔离”站
- proftpd中Limit的使用
- 浅析在FreeBSD中建立chroot的FTP
阅览排行
用Java实现FTP服务器
www.jz123.cn 2008-07-28 来源: 中国建站 编辑整理 我要投递新闻
STOR 命令的处理也是同样的过程,只是方向正好相反。
◆ DELE (DELETE)命令处理代码如下:
if(str.startsWith("DELE")){
str = str.substring(4);
str = str.trim();
File file = new File(dir,str);
boolean del = file.delete();
out.println("250 delete command successful");
}
DELE 命令用于删除服务器上的指定文件。
◆ LIST命令处理代码如下:
if(str.startsWith("LIST")) {
try{
out.println("150 ASCII data");
Socket tempSocket = new Socket(host,tempPort);
PrintWriter out2= new PrintWriter(tempSocket.getOutputStream(),true);
File file = new File(dir);
String[] dirStructure = new String[10];
dirStructure= file.list();
String strType="";
for(int i=0;iif( dirStructure[i].indexOf(".") == -1) {
strType = "d ";}
else
{strType = "- ";}
out2.println(strType+dirStructure[i]);
}
tempSocket.close();
out.println("226 transfer complete");
}
catch(IOException e){}
LIST 命令用于向客户端返回服务器中工作目录下的目录结构,包括文件和目录的列表。处理这个命令时,先创建一个临时的套接字向客户端发送目录信息。这个套接字的目的端口号缺省为1,然后为当前工作目录创建File 对象,利用该对象的list()方法得到一个包含该目录下所有文件和子目录名称的字符串数组,然后根据名称中是否含有文件名中特有的“.”来区别目录和文件。最后,将得到的名称数组通过临时套接字发送到客户端。
上一篇:FTP服务器端注意事项及常见名词解释 下一篇:使用Serv-U创建FTP服务器