简体   繁体   English

将文件上传到服务器根目录

[英]Upload file into Server Root directory

I really have a problem while trying to upload a file into my servers root directory. 尝试将文件上传到服务器根目录时,我确实遇到了问题。 I know that the File-Class cannot handle directorys like http://localhost:8080/rootdata . 我知道File-Class无法处理类似http://localhost:8080/rootdata

Please do not tell me not to upload files to the root. 请不要告诉我不要将文件上传到根目录。 I just want to know how to do that. 我只想知道该怎么做。

So is there a way bringing up my files in that root directory via java? 那么有没有办法通过Java在该根目录中启动我的文件?

Thanks for any help 谢谢你的帮助

Use Apache's FTP library to browse and retrieve files from your servers filesystem. 使用Apache的FTP库浏览和检索服务器文件系统中的文件。 You can list out all the files in the root directory by using: 您可以使用以下命令列出根目录中的所有文件:

.listFiles()

Example: 例:

String hostname = properties.getProperty("FTP_SERVER");
        String user = properties.getProperty("FTP_USER");
        String passwd = properties.getProperty("FTP_PASSWD");
        FTPClient client = new FTPClient();
        client.connect(hostname);
        client.login(user, passwd);
        String reply = client.getStatus();
        System.out.println(reply);
        client.enterRemotePassiveMode();
        client.changeWorkingDirectory("/");
        FTPFile[] files = client.listFiles();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM