?? fileuploadutil.java
字號(hào):
package com.topking.ftp.util;
import java.io.File;
import java.io.IOException;
import sun.net.ftp.FtpClient;
public class FileUpLoadUtil {
public static void upLoad(String Rpath,String fileName,FtpClient ftp){
System.out.println("Rpath:"+Rpath);
System.out.println("fileName:"+fileName);
String localRootPath = PathUtil.rePlace(fileName);
System.out.println("localRootPath:"+localRootPath);
String remoteRootPath = Rpath;
File rootFile = new File(fileName);
if(rootFile.isDirectory()){
if(!createDir(remoteRootPath,PathUtil.getFolderName(fileName),ftp)){
System.out.println("創(chuàng)建遠(yuǎn)程根文件夾"+remoteRootPath+fileName+"/失敗");
return;
}
remoteRootPath = remoteRootPath+PathUtil.getFolderName(fileName)+"/";
String[] fs = rootFile.list();
for(int i=0;i<fs.length;i++){
File subFile = new File(localRootPath+"/"+fs[i]);
if(subFile.isDirectory()){
upLoad(remoteRootPath,localRootPath+"/"+fs[i],ftp);//遞歸
}//end if
else{
//文件上傳
System.out.println("上傳文件"+i);
}
}//end for
}else{
//文件上傳
System.out.println("上傳文件");
}
}
public static boolean createDir(String Rpath,String fileName,FtpClient ftp){
boolean flag = false;
if(!isExsitDir(Rpath+fileName,ftp)){
try {
String cmd = "MKD "+Rpath+fileName+"/"+"\r\n";
System.err.println("CMD : "+cmd);
ftp.sendServer(cmd);
ftp.binary();
int reply = ftp.readServerResponse();
System.err.println("Reply : "+reply);
flag = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return flag;
}
public static boolean isExsitDir(String dir,FtpClient ftpClient){
try {
ftpClient.cd(dir);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("文件夾不存在.......................");
// e.printStackTrace();
return false;
}
return true;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -