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;
- }
转载自: http://blog.csdn.net/android_robot/article/details/7094420