1

We are using Commons VFS API for file transfer between different servers. The Code works perfectly for the Linux Servers.

But We are having URL Syntax issues for Windows Servers. We tried below list of URL types but all of them resulted in Invalid Absolute URI Error,

sftp://user@IP:C:\temp

sftp://user@IP/C:\temp

sftp://user@IP\C:\temp

stfp://user@IP/temp -- Resulted in Could not determine the type of file

All these errors started another doubt in our minds, that whether VFS supports connecting to Windows File System through SFTP.

Any help in this regard is appreciated.

anand_206
  • 31
  • 4

1 Answers1

1

You need to use forward slashes to separate host from path and the different path elements.

The way to specify a dos drive depends a bit on the SFTP server you use. Some of them use cygwin path like /cygdrive/c/temp, others use /C/Temp and some use a base directory somewhere below the base path.

I am not sure if there is one which actually allows the drive letter with colon, but anyway in case you care, you need to escape the : (colon) with %3a (the hex code):

sftp://user@ip/C%3a/temp

If you do not want to quote all possible characters in an URL yourself, you can use the URI class like suggested in this answer: (But you need to make sure to start the path string with a / (slash) to make it absolute.)

URI uri1 = new URI("sftp", "user:p@ssword", "127.0.0.1", -1, "/C:/temp", null, null);
fsm.resolveFile(uri1.toString(), opts);

or when you do not want to convert the local path, you can use:

String path = new File("C:\\temp").toURI().getPath();
URI uri2 = new URI("sftp", "user:p@ssword", "127.0.0.1", -1, path, null, null);
fsm.resolveFile(uri2.toString(), opts);

Please let me know which path syntax works.

Community
  • 1
  • 1
eckes
  • 10,103
  • 1
  • 59
  • 71