JavaはFTP上にファイルを作成する.
1321 ワード
JavaはFTP上でファイルを作成する
public boolean createDirectory() {
boolean flag = false;
// FTP
FTPClient ftpClient = new FTPClient();
try {
// FTP
ftpClient.connect(this.ftpServerIP);
//
if (ftpClient.login(this.ftpName, this.ftpPassword)) {
// , FTP "xxx"
if (this.ftpPath != null && this.ftpPath.compareTo("") != 0
&& ftpClient.changeWorkingDirectory(this.ftpPath)) {
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
String time = f.format(new Date());
String reTransmitFolderName = time + "_Folder";
ftpClient.makeDirectory(reTransmitFolderName);
flag = true;
}
}
} catch (SocketException e) {
e.printStackTrace();
flag = false;
} catch (IOException e) {
e.printStackTrace();
flag = false;
} catch (Exception e) {
e.printStackTrace();
flag = false;
} finally {
try {
//
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
return flag;
}