吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1736|回复: 2
收起左侧

[Java 转载] 分享一段FTP服务器删除文件代码

[复制链接]
sanmu8 发表于 2020-4-16 11:57
/**
*
* @Param FileName 文件名
* @param host FTP服务器hostname
* @param port FTP服务器端口
* @param username FTP用户名
* @param password FTP密码
* @param basePath 文件所在路径
* @return
*/
public static boolean deleteFile(String FileName,String host, int port, String username, String password, String basePath
                    ) {
   boolean success = false;
   FTPClient ftp = new FTPClient();
   ftp.setControlEncoding("GBK");
   try {
      int reply;
      ftp.connect(host, port);// 连接FTP服务器
      ftp.login(username, password);// 登录
      reply = ftp.getReplyCode();
      if (!FTPReply.isPositiveCompletion(reply)) {
         ftp.disconnect();
         return success;
      }
      ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
      ftp.makeDirectory(basePath);
      ftp.changeWorkingDirectory(basePath);
      success = ftp.deleteFile(FileName);
      ftp.logout();
   } catch (IOException e) {
      e.printStackTrace();
   } finally {
      if (ftp.isConnected()) {
         try {
            ftp.disconnect();
         } catch (IOException ioe) {
         }
      }
   }
   return success;
}
前段时间在网上找了一段时间才找到,本人较菜,记录一下,防止以后有人遇到同样需求

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

independence 发表于 2020-5-14 22:40
加油加油
早早早丶 发表于 2020-11-30 11:21
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-15 05:36

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表