java ftp
Posted tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java ftp相关的知识,希望对你有一定的参考价值。
1.添加依赖
commons-net-3.6.jar
2.获取ftp客户端
ftpClient = new FTPClient();
ftpClient.connect(ip, port);
ftpClient.login(username, password);
ftpClient.setBufferSize(8096);
ftpClient.changeWorkingDirectory("/root");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
3.下载
remote = new String((ftpClient.printWorkingDirectory() + filepath).getBytes("gbk"), "ISO885901");
file = new File(local);
ftpClient.retrieveFile(remote, new FileOutputStream(file));
4.上传
remote = new String((ftpClient.printWorkingDirectory() + filepath).getBytes("gbk"), "ISO885901");
file = new File(local);
ctpClient.makeDirectory((ftpClient.printWorkingDirectory() + filepath).getBytes("gbk"), "ISO885901");
ftpClient.storeFile(remote, new FileOutputStream(file));
以上是关于java ftp的主要内容,如果未能解决你的问题,请参考以下文章