Apache Commons FTPClient,检查远程目录是否存在并获取权限(linux - unix)
是否可以使用 FTPClient (Apache commons-net) 检查远程目录是否存在?
我想做这样的事情:
ftp.isDirectory(String path) //returns true, false
然后获取目录的权限(chmod):
ftp.getPermisions(String path) //returns -rwxr-xr-x
Is it possible with FTPClient (Apache commons-net) to check if a remote directory exists?
I want to do something like this:
ftp.isDirectory(String path) //returns true, false
And then get permissions (chmod) of directory:
ftp.getPermisions(String path) //returns -rwxr-xr-x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试将工作目录更改为您需要检查的目录:
Try to change the working directory to the directory you need to check:
您只需要检查
ftpClient.cwd("your Directory Name")
,这将返回整数值
250
- 如果文件存在或
550
如果文件不存在,代码> -例如,
What you just Need to check is just
ftpClient.cwd("your Directory Name")
this will return you integer values
250
- If File ExistsOR
550
- If File Doesn't ExistFor Example,
我也需要弄清楚这一点,但在玩了一会儿之后,我想我已经弄清楚了。我还没有测试过这个,但我认为它会完成这个技巧
希望这有效/有帮助。这似乎也是一种相当多余的方法,因此可能有更好的方法。我不知道,我是这个库和 android 的新手
I needed to figure this out too, but after doing a little play, I think I figured it out. I havent gotten to test this yet, but I think it will do the trik
Hope this works/helps. This also seems like a pretty redundant way, so there may be a better way of doing it. Idk, im new to this library and android
如果远程主机支持,最简单的方法是 mlistFile()。
If the remote host supports it, the simplest method is mlistFile().
这是我查找给定路径是否代表目录或文件的方法。
Here is my take on to find whether given path represents a directory or a file.