Java实现FTP上传下载文件的工具包有很多,这里我采用Java自带的API,实现FTP上传下载文件。另外JDK1.7以前的版本与其之后版本的API有了较大的改变了。

例如:

JDK1.7之前 JDK1.7
ftpClient = new FtpClinet() ftpClient = FtpClient.create(ip)
ftpclient.login(user,password) ftpclient.login(user,null,password)
ftpclient.binary() ftpClient.setBinaryType();

一. 连接FTP服务器

class FTPUtil {
//FTP服务器IP地址
;
   4:     
//FTP服务器端口
int FTP_PORT = 21;
   7:     
//FTP服务器用户名
;
  10:     
//密码
;
  13:     
  14:     
static FtpClient getConnect()
  16:     {
try {
  18:             FtpClient ftpClient = FtpClient.create(FTP_HOST);
  19:             ftpClient.login(FTP_USER, FTP_PASSWORD.toCharArray());
return ftpClient;
catch (FtpProtocolException e) {
// TODO Auto-generated catch block
  23:             e.printStackTrace();
);
return null;
catch (IOException e) {
// TODO Auto-generated catch block
  28:             e.printStackTrace();
);
return null;
  31:         }
  32:         
  33:     }
  34: }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2021-12-13
  • 2021-11-11
  • 2021-12-12
  • 2021-12-20
相关资源
相似解决方案