FTPClientファイルアップロードの問題

問題:
1、FTPClient文件上传方法storeFile(remoteFilePath, input)不会自动创建文件夹。
2、FTPClient创建文件夹方法makeDirectory(dirName)不支持创建多层级文件夹。
比如:文件路径:/C6666666/2019-06-12/20190612013246.jpg 
直接调用storeFile(remoteFilePath, input)方法进行文件上传,
如果存在/C6666666/2019-06-12文件夹,则上传成功,
如果本身不存在这个层级文件夹,则会抛出异常。
试想,调用makeDirectory(dirName)方法去创建该多层级文件夹,结果会抛出异常。
ソリューション:

マルチレベルのフォルダパスは、フォルダが存在しない場合は、それが作成される単一レベルのフォルダを切りました。ケースフォルダのアップロードファイルを成功させることができますがあります。

 //在ftp服务中创建文件夹,如果存在则不创建 
 //remoteFilePath:/C6666666/2019-06-12/20190612013246.jpg
 String[] fileNames = remoteFilePath.split("/");
 for (Integer i = 0; i < fileNames.length - 1; i++) {
 	  //创建文件夹,不支持创建多层级文件夹。
      ftp.makeDirectory(fileNames[i]);
      //改变工作目录,即使用刚创建成功的目录
      ftp.changeWorkingDirectory(fileNames[i]);
 }
 //上传文件
 if(!existFile(ftp,remoteFilePath)){
 	  //upload 封装了storeFile(remoteFilePath, input)方法
      upload(ftp,fileNames[fileNames.length - 1], localFilePath);
 }else{
     System.out.println("[存在]:"+remoteFilePath);
 }

要是还有不太明白的地方请留言,评论必回
要是对我的文章感兴趣的话,关注一下吧,谢谢!

前:FTPクライアントがサーバーにファイルをアップロード

次へ:Linuxの基本的なコマンド

おすすめ

転載: blog.csdn.net/chen_2890/article/details/93418673