在Java中通过FTP创建文件夹层次结构 [英] Create a folder hierarchy through FTP in Java

查看:1591
本文介绍了在Java中通过FTP创建文件夹层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有Java可用的功能在远程FTP服务器上创建文件夹层次结构。 Apache Commons提供了一个FTP客户端,但我找不到创建目录层次结构的方法。
它确实允许创建一个目录(makeDirectory),但创建整个路径似乎并不存在。
我希望这样做的原因是因为有时目录层次结构的某些部分尚不可用,在这种情况下,我想创建层次结构的缺失部分,然后切换到新创建的目录。

解决方案

您必须使用 FTPClient.changeWorkingDirectory 来确定目录是否存在,然后 FTPClient.makeDirectory 如果调用 FTPClient.changeWorkingDirectory 返回 false

您需要以上述方式递归地遍历目录树在每个级别根据需要创建目录。


Is there readily available functionality for Java to create a folder hierarchy on a remote FTP server. Apache Commons does provide an FTP client, but I can't find a method for creating a directory hierarchy. It does allow for creating a single directory (makeDirectory), but creating an entire path does not seem to be in there. The reason I want this is because sometimes part of a directory hierarchy is not (yet) available and in such a case I want to create the missing part of the hierarchy and then change to that newly created directory.

解决方案

You have to use a combination of FTPClient.changeWorkingDirectory to figure out if the directory exists, then FTPClient.makeDirectory if the call to FTPClient.changeWorkingDirectory returns false.

You need to recursively walk the directory tree in the manner described above at each level create the directory as required.

这篇关于在Java中通过FTP创建文件夹层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆