ftp创建文件-java
private static void uploadFileToFTP(String file1, String file2,
String fileName, String content) throws Exception {
InputStream is = new ByteArrayInputStream((content).getBytes());
FTPClient ftp = new FTPClient();
ftp.connect(server);
ftp.login(userName, userPassword);
ftp.enterLocalPassiveMode();
FTPFile[] files = ftp.listFiles();
boolean flag = false;
for (FTPFile file : files) {
if (file.getName().getBytes().equals(file1.getBytes())) {
flag = true;
break;
}
}
if (!flag) {
ftp.makeDirectory(file1);
}
ftp.changeWorkingDirectory(file1 + "/");
files = ftp.listFiles();
flag = false;
for (FTPFile file : files) {
if (file.getName().getBytes().equals(file2.getBytes())) {
flag = true;
break;
}
}
if (!flag) {
ftp.makeDirectory(file2);
}
ftp.changeWorkingDirectory(file2 + "/");
ftp.storeFile(fileName, is);
ftp.logout();
}