0

I use Apache Commons to retrieve files from a remote server using sftp. I the URL to the file is stashed away and serialized. When deserializing it I get the following exception

java.net.MalformedURLException: unknown protocol: sftp

The same thing happens when I do this

new URL(url.toString());

Where url is the url to the file retrieved by apache commons. I have aded the dependency to both apache commons and jsch. How can I solve this?

Eric Lundmark
  • 229
  • 3
  • 13

2 Answers2

0

From java documentation :

If this class does not exist, or if the class exists but it is not a subclass of URLStreamHandler, then a MalformedURLException is thrown. Protocol handlers for the following protocols are guaranteed to exist on the search path :- http, https, ftp, file, and jar

Seems sftp is not supported.

mayr
  • 451
  • 6
  • 14
  • 1
    But how can I have a URL with sftp as protocol turn it into a string and then when converting it back get an error? How could it be created from the beginning? – Eric Lundmark Jul 11 '14 at 07:41
0

I think a better alternative would be http://www.jcraft.com/jsch/ In case you need or you are forced to use Apache libraries, there is an example how to do it http://www.mysamplecode.com/2013/06/sftp-apache-commons-file-download.html

This should help you to get oriented, what do you trying to achieve.

bodo
  • 827
  • 6
  • 19