FtpOutputStream or similar in standard Java

青春壹個敷衍的年華 提交于 2019-12-23 03:08:07

问题


is there any possible way to write a file to a FTP directory using some sort of OutputStream without having to write a local file first?

I've found some 3rd party libraries which achieve this, but I was wondering if there is some java "standard" class that makes it possible, I mean, some class that is packaged into the standar Java API.

Thank you!!


回答1:


URL url = new URL("ftp://user:pass@ftp.something.com/file.txt;type=i");
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream(); // To download
OutputStream os = urlc.getOutputStream(); // To upload



回答2:


  • If you should only write/read files is better to use java.net.URL class.
  • If seems you should manipulate files/directories via FTP you must use 3rd party library.

The best practice is building abstract layer to not depend from FTP solution.

As for me the best tool for Java FTP is http://www.sauronsoftware.it/projects/ftp4j/



来源:https://stackoverflow.com/questions/12835716/ftpoutputstream-or-similar-in-standard-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!