跪求Java大神解答该程序出现的错误

sinat_31890859 2016-10-07 05:12:23
public class ftpServer extends Thread {
private Socket socketClient;
private int counter;
private static String initDir;
public static void main(String[] args){
//ftpServer ftpserver;
//ftpserver=new ftpServer();
if(args.length != 0) {
initDir = args[0];
}
else{ initDir = "c:"; }
int i = 1;
try{
System.out.println("ftp server started!");//监听21号端口
ServerSocket s = new ServerSocket(21);
for(;;){//接受客户端请求
Socket incoming = s.accept();//创建服务线程
new ftpServer(incoming,i).start();
i++;
}
}catch(Exception e){}
if(str.startsWith("USER")){
user = str.Substring(4);
user = user.trim();
System.out.println("331 Password");
}
if(str.startsWith("PASS"))
System.out.printstream("230 User "+ user +" logged in.");
if(str.startsWith("CWD")){
String str1 = str1.Substring(3);
dir= dir +"/"+str1.trim();
System.out.println("250 CWD command succesful");
}
if(str.startsWith("CDUP")){
int n = dir.lastIndexOf("/");
dir = dir.substring(0,n);
System.out.println("250 CWD command succesful");
}
if(str.startsWith("QUIT")) {
System.out.println("GOOD BYE");
done = true;
}
if(str.startsWith("PORT")) {
System.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;l
str1 = str2+str.charAt(l);
}
for(int l=j+1;l<=i;l++){
String str2 = str2+str.charAt(l);
}
tempPort = Integer.parseInt(String str1)*16*16+Integer.parseInt(str2);
}
if(str.startsWith("TYPE")){
System.out.println("200 type set");
}
if(str.startsWith("RETR")){
System.out.println("150 Binary data connection");
String 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();
System.out.println("226 transfer complete");
outFile.close();
tempSocket.close();
}
catch(IOException e){}
}
if(str.startsWith("STOR")){
System.out.println("150 Binary data connection");
String 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();
System.out.println("226 transfer complete");
inFile.close();
tempSocket.close();
}
catch(IOException e){}
}
if(str.startsWith("DELE")){
str = str.substring(4);
str = str.trim();
File file = new File(dir,str);
boolean del = file.delete();
System.out.println("250 delete command successful");
}
if(str.startsWith("LIST"))
try{
System.out.println("150 ASCII data");
Socket tempSocket = new Socket(host,tempPort);
PrintWriter out2= new PrintWriter(tempSocket.getOutputStream(),true);
File dir = new File("dir");
String[] dirStructure = new String[10];
dirStructure= file.list();
String strType="";
for(int i=0;i<10;i++)
if( dirStructure[i].indexOf(".") == -1) {
strType = "d ";}
else
{strType = "- ";}
out2.println(strType dirStructure[i]);
}
tempSocket.close();
System.out.println("226 transfer complete");
}
catch(IOException e){}
}
}
...全文
113 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧