I'm writing some Java code (using JSch library) to SFTP into a remote Windows machine and copy a file to my local Windows folder.
When specifying the path to the file on the remote machine, I'm forced to specify the path in the format /C/temp/myfile.txt
instead of C:\temp\myfile.txt
.
Questions:
Could you tell me what this format is? Is there a name for it?
Could you tell me if it's possible to use any other format for the path? I'd like to be able to specify the path as C:\temp\myfile.txt
, so it's not apparent to the users whether the file is being SFTP'd from a remote machine at all. I'm guessing I'd have to parse/split/replace characters in the path as the FTP get command wouldn't understand this path format.
thanks.
SFTP protocol mandates that /
must be used as a path separator.
See SFTP specification:
This protocol represents file names as strings. File names are assumed to use the slash ('/') character as a directory separator.
File names starting with a slash are "absolute", and are relative to the root of the file system. Names starting with any other character are relative to the user's default directory (home directory). Note that identifying the user is assumed to take place outside of this protocol.
It's the SFTP server that maps real OS-specific paths on the server's file system to a syntax, that conforms to SFTP specification.
You have to use the syntax, that the server's authors have chosen to use.
So in all cases you have to map the \
to /
.
And you may need to remove the :
. Though that can actually be configurable. Many (particularly Windows) SFTP servers have a configuration, that allows you to map a virtual SFTP path to a real path. In that case, you may be able to map /C:/
to C:\
.
In any case, your question is actually not about JSch, let alone Java, but about your SFTP server.
See also FAQ for my WinSCP SFTP client: How do I change drive on the remote panel?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With