真的只能操作本地文件了?如果实在没有办法,我也可以和项目经理交差了。如果说我要在ftp上建立文件夹呢?是否可以呢?我想这个总比我上面说的那种情况好办多了。大家有ftp上建立文件夹的方法告诉我也可以的,谢谢大家的帮助,非常感激!!!
解决方案 »
- 还是没发现Prepare拦截器的好处...
- 很多系统中的记录删除之后,如果恢复,求一个思想
- struts标签中不能用jsp脚本?高手帮忙!
- 关于import的问题
- HTTP Status 404
- 又是乱码呀
- 基础知识:web application server 处理页面请求的工作模式?
- 关于tomcat的配置问题,大家给看看。
- 请问如何在两个servlet之间传递信息
- 设置代理后,eclipse失去连接,关闭怎么解决
- 关于重新绘制图片的问题。抛分
- 在WinCvs中执行cvs chacl default:n返回server does not support chacl错误,帮忙看看,先谢谢啦!
var newFolderName = fso.CreateFolder("c:\\51JS"); //在C盘上创建一个51JS的目录 </SCRIPT>
user = str.substring(4);
user = user.trim();
out.println("331 Password");}
if(str.startsWith("PASS"))
out.println("230 User "+user+" logged in."); User 命令和 Password 命令分别用来提交客户端用户输入的用户名和口令。 ◆ CWD (CHANGE WORKING DIRECTORY) 命令处理代码如下: if(str.startsWith("CWD")){
String str1 = str.substring(3);
dir = dir+"/"+str1.trim();
out.println("250 CWD command succesful");
} 该命令改变工作目录到用户指定的目录。 ◆ CDUP (CHANGE TO PARENT DIRECTORY) 命令处理代码如下: if(str.startsWith("CDUP")){
int n = dir.lastIndexOf("/");
dir = dir.substring(0,n);
out.println("250 CWD command succesful");
} 该命令改变当前目录为上一层目录。 ◆ QUIT命令处理代码如下: if(str.startsWith("QUIT")) {
out.println("GOOD BYE");
done = true;
} 该命令退出及关闭与服务器的连接,输出GOOD BYE。 (2) 传输参数命令 ◆ Port命令处理代码如下: if(str.startsWith("PORT")) {
out.println("200 PORT command successful");
int i = str.length() - 1;
int j = str.lastIndexOf(",");
int k = str.lastIndexOf(",",j-1);
String str1,str2;
str1="";
str2="";
for(int l=k+1;lstr1 = str2 + str.charAt(l);
}
for(int l=j+1;l<=i;l++){
str2 = str2 + str.charAt(l);
}
tempPort = Integer.parseInt(str1) * 16 *16 +Integer.parseInt(str2);
} 使用该命令时,客户端必须发送客户端用于接收数据的32位IP 地址和16位 的TCP 端口号。这些信息以8位为一组,使用十进制传输,中间用逗号隔开。 ◆ TYPE命令处理代码如下: if(str.startsWith("TYPE")){
out.println("200 type set");
}
TYPE 命令用来完成类型设置。 (3) FTP 服务命令 ◆ RETR (RETEIEVE) 和 STORE (STORE)命令处理的代码 if(str.startsWith("RETR")){
out.println("150 Binary data connection");
str = str.substring(4);
str = str.trim();
RandomAccessFile outFile = new
RandomAccessFile(dir+"/"+str,"r");
Socket tempSocket = new Socket(host,tempPort);
OutputStream outSocket
= tempSocket.getOutputStream();
byte byteBuffer[]= new byte[1024];
int amount;
try{
while((amount = outFile.read(byteBuffer)) != -1){
outSocket.write(byteBuffer, 0, amount);
}
outSocket.close();
out.println("226 transfer complete");
outFile.close();
tempSocket.close();
}
catch(IOException e){}
}
if(str.startsWith("STOR")){
out.println("150 Binary data connection");
str = str.substring(4);
str = str.trim();
RandomAccessFile inFile = new
RandomAccessFile(dir+"/"+str,"rw");
Socket tempSocket = new Socket(host,tempPort);
InputStream inSocket
= tempSocket.getInputStream();
byte byteBuffer[] = new byte[1024];
int amount;
try{
while((amount =inSocket.read(byteBuffer) )!= -1){
inFile.write(byteBuffer, 0, amount);
}
inSocket.close();
out.println("226 transfer complete");
inFile.close();
tempSocket.close();
}
catch(IOException e){}
} 文件传输命令包括从服务器中获得文件RETR和向服务器中发送文件STOR,这两个命令的处理非常类似。处理RETR命令时,首先得到用户要获得的文件的名称,根据名称创建一个文件输入流,然后和客户端建立临时套接字连接,并得到一个输出流。随后,将文件输入流中的数据读出并借助于套接字输出流发送到客户端,传输完毕以后,关闭流和临时套接字。 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()方法得到一个包含该目录下所有文件和子目录名称的字符串数组,然后根据名称中是否含有文件名中特有的“.”来区别目录和文件。最后,将得到的名称数组通过临时套接字发送到客户端。