FTPClient (Apache commons-net) でリモート ディレクトリが存在するかどうかを確認することはできますか?
私はこのようなことをしたい:
ftp.isDirectory(String path) //returns true, false
そして、ディレクトリのパーミッション (chmod) を取得します:
ftp.getPermisions(String path) //returns -rwxr-xr-x
FTPClient (Apache commons-net) でリモート ディレクトリが存在するかどうかを確認することはできますか?
私はこのようなことをしたい:
ftp.isDirectory(String path) //returns true, false
そして、ディレクトリのパーミッション (chmod) を取得します:
ftp.getPermisions(String path) //returns -rwxr-xr-x
作業ディレクトリを確認する必要があるディレクトリに変更してみてください。
boolean directoryExists = FTPClient.changeWorkingDirectory("path/to/somedir")
確認する必要があるのは、ftpClient.cwd("your Directory Name")
これは整数値を返します
250
- ファイルが存在する場合
また
550
- ファイルが存在しない場合
例えば、
if(ftpClient.cwd(uploadDirectoryPath)==550){
System.out.println("Directory Doesn't Exists");
}else if(ftpClient.cwd(uploadDirectoryPath)==250){
System.out.println("Directory Exists");
}else{
System.out.println("Unknown Status");
}
私もこれを理解する必要がありましたが、少し遊んだ後、私はそれを理解したと思います. 私はまだこれをテストしていませんが、うまくいくと思います
FTPFile file[];
file = new FTPFile[ftpClient.listFiles().length];
for (int i = 0; i<file.length; i++) {
if (file[i].getName() == "directory name") {
if (file[i].isDirectory()) {
//Do stuff if it is a directory here
if (file[i].hasPermission(access, permission) {
//Do whatever you want with permissions - access and permission arguments are int's
}
}
}
}
これがうまくいく/役立つことを願っています。これもかなり冗長な方法のように思えるので、もっと良い方法があるかもしれません。Idk、このライブラリとアンドロイドは初めてです
リモート ホストがサポートしている場合、最も簡単な方法はmlistFile()です。
if (ftpClient.featureValue("MLST") != null) {
FTPFile file = ftpClient.mlistFile(null);
boolean b = file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION);
}