可以直接通过 FTPClient 方法进行文件上传。工具代码举例:
/**
* 上传文件
*
* @param fileName
* @param date
* @param plainFilePath 文件路径路径
* @param filepath
* @return
* @throws Exception
*/
public static String encodeAESFileUploadByFtp(String plainFilePath, String fileName, String date,String filepath) throws Exception {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
FTPClient ftpClient = new FTPClient();
String bl = "false";
try {
fis = new FileInputStream(plainFilePath);
bos = new ByteArrayOutputStream(fis.available());
byte[] buffer = new byte[1024];
int count = 0;
while ((count = fis.read(buffer)) != -1) {
bos.write(buffer, 0, count);
}
bos.flush();
Log.info("加密上传文件开始");
byte[] bytes = encodeAES(key, bos.toByteArray());
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
Log.info("连接远程上传服务器"+CMBCUtil.CMBCHOSTNAME+":"+2021);
ftpClient.connect(CMBCUtil.CMBCHOSTNAME, 2021);
ftpClient.login(CMBCUtil.CMBCL