Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFTP path format versus local path format

Tags:

java

sftp

jsch

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:

  1. Could you tell me what this format is? Is there a name for it?

  2. 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.

like image 614
plz_do_the_needful Avatar asked Aug 15 '17 10:08

plz_do_the_needful


Video Answer


1 Answers

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?

like image 151
Martin Prikryl Avatar answered Oct 21 '22 14:10

Martin Prikryl