博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从ftp上传下载文件(一)
阅读量:7081 次
发布时间:2019-06-28

本文共 2815 字,大约阅读时间需要 9 分钟。

/**

  * 从FTP中下载文件至本地路径 remoteFileName FTP服务器上文件名称 localFileName 本地文件名
  *
  * @return
  */
 private boolean getFileFromFtp(String remoteFileName, String localFileName)
   throws Exception {

  boolean flag = false;

  FtpConfig ftpConfig = new FtpConfig();

  String location = "";

  String password = "";
  int port = 0;
  String server = "";
  String userName = "";

  if (StringUtils.isBlank(location)) {

   if (SpringContextHolder.getApplicationContext().getEnvironment()
     .acceptsProfiles(ProfileCode.PROD.name())) {
    location = ConfKit.getApp("ftp_location");
   } else if (SpringContextHolder.getApplicationContext()
     .getEnvironment().acceptsProfiles(ProfileCode.QA.name())) {
    location = ConfKit.getAppQA("ftp_location");
   } else {
    location = ConfKit.getAppQA("ftp_location");
   }
  }

  if (StringUtils.isBlank(password)) {

   if (SpringContextHolder.getApplicationContext().getEnvironment()
     .acceptsProfiles(ProfileCode.PROD.name())) {
    password = ConfKit.getApp("ftp_password");
   } else if (SpringContextHolder.getApplicationContext()
     .getEnvironment().acceptsProfiles(ProfileCode.QA.name())) {
    password = ConfKit.getAppQA("ftp_password");
   } else {
    password = ConfKit.getAppQA("ftp_password");
   }
  }

  if (port == 0) {

   if (SpringContextHolder.getApplicationContext().getEnvironment()
     .acceptsProfiles(ProfileCode.PROD.name())) {
    port = Integer.valueOf(ConfKit.getApp("ftp_port"));
   } else if (SpringContextHolder.getApplicationContext()
     .getEnvironment().acceptsProfiles(ProfileCode.QA.name())) {
    port = Integer.valueOf(ConfKit.getAppQA("ftp_port"));
   } else {
    port = Integer.valueOf(ConfKit.getAppQA("ftp_port"));
   }
  }

  if (StringUtils.isBlank(server)) {

   if (SpringContextHolder.getApplicationContext().getEnvironment()
     .acceptsProfiles(ProfileCode.PROD.name())) {
    server = ConfKit.getApp("ftp_server");
   } else if (SpringContextHolder.getApplicationContext()
     .getEnvironment().acceptsProfiles(ProfileCode.QA.name())) {
    server = ConfKit.getAppQA("ftp_server");
   } else {
    server = ConfKit.getAppQA("ftp_server");
   }
  }

  if (StringUtils.isBlank(userName)) {

   if (SpringContextHolder.getApplicationContext().getEnvironment()
     .acceptsProfiles(ProfileCode.PROD.name())) {
    userName = ConfKit.getApp("ftp_userName");
   } else if (SpringContextHolder.getApplicationContext()
     .getEnvironment().acceptsProfiles(ProfileCode.QA.name())) {
    userName = ConfKit.getAppQA("ftp_userName");
   } else {
    userName = ConfKit.getAppQA("ftp_userName");
   }
  }
 /*  从上面读的基本配置信息,具体例子如下

 location = "/deve";

  password = "PWD";
  port = 21;
  server = "IP";
  userName = "samsungshare";*/

  ftpConfig.setLocation(location);
  ftpConfig.setPassword(password);
  ftpConfig.setPort(port);
  ftpConfig.setServer(server);
  ftpConfig.setUsername(userName);
  FtpKit ftpKit = new FtpKit();
  ftpKit.connectServer(ftpConfig);
  // 将远程FTP中文件下载到本地目录中
  flag = ftpKit.download(remoteFileName, localFileName);
  ftpKit.closeServer();
  return flag;
 }

转载地址:http://qwtml.baihongyu.com/

你可能感兴趣的文章
绘制程序流程图笔记
查看>>
leetcode — remove-duplicates-from-sorted-array-ii
查看>>
Java 线程 — ConcurrentLinkedQueue
查看>>
apache手动安装
查看>>
Centos7.2安装搜狗拼音
查看>>
HTTP长连接和短连接
查看>>
python-数据类型的补充
查看>>
(赛码"BestCoder"杯中国大学生程序设计冠军赛)GCD
查看>>
软工第二周随笔
查看>>
QT+VS开发环境的安装和可能出现的build错误(转)
查看>>
ARC中strong 和weak知识总结
查看>>
宏定义 注意
查看>>
680. Valid Palindrome II
查看>>
Uva 537 - Artificial Intelligence?
查看>>
在O(1)时间删除链表结点
查看>>
Android上实现MVP模式的途径
查看>>
CALL transaction 的用法-传内表
查看>>
System program tools
查看>>
mysql+mycat搭建稳定高可用集群,负载均衡,主备复制,读写分离
查看>>
CSS 渐变动画
查看>>