当前位置: 首页 > 工具软件 > ftp4j > 使用案例 >

ftp4j

洪飞驰
2023-12-01
http://www.sauronsoftware.it/projects/ftp4j/
使用开源项目:ftp4j
  <</span>http://www.sauronsoftware.it/projects/ftp4j/>
  import java.io.File;
  import it.sauronsoftware.ftp4j.FTPClient;
  import it.sauronsoftware.ftp4j.FTPFile;
  public class JavaFtp {
  private FTPClient client =null;
  public void init(){
  try {
  client = new FTPClient();
  client.connect("192.168.1.248", 21);
  client.login("db2inst1", "db2inst1");
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  public static void main(String[] args) {
  try {
  JavaFtp javaFtp=new JavaFtp();
  javaFtp.init();
  javaFtp.download("E://test", "/test/");
  javaFtp.close();
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  public void download(String localpath,String clientpath){
  try {
  if(clientpath!=null&&clientpath.length()>=0){
  client.changeDirectory(clientpath);
  }
  FTPFile[] list = client.list();
  for(int i=0;i
  FTPFile file = list[i];
  System.out.println(file.getType());
  if(file.getType()==FTPFile.TYPE_DIRECTORY){
  File temp=new File(localpath+File.separator+file.getName());
  if(!temp.exists()){
  temp.mkdir();
  }
  download(localpath+File.separator+file.getName(),file.getName());
  }
  else if(file.getType()==FTPFile.TYPE_FILE){
  File localfile=new File(localpath+File.separator+file.getName());
  client.download(file.getName(), localfile);
  }
  }
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  public void close(){
  try {
  client.disconnect(true);
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  }
 类似资料:

相关阅读

相关文章

相关问答