2

I have a windows VM which has been configured with the mksnt toolkit. So what that would imply is my path would become C:/abc/xyz

I am trying to connect from a linux box using Jsch utilty to this windows machine remotely. I am able to connect successfully and when I try to check for a particular directory path, it says it does not exist. However, the path does exist on the windows box.

Following is my Jsch code that looks for the destination directory -

SftpATTRS dirAttributes=null;
try{
    testLog.info("Looking for directory :"+destinationDir);
    dirAttributes = sftpc.stat(destinationDir);
} catch(SftpException s){
    testLog.info("Directory does not exists !!!\n"+s.fillInStackTrace().toString());;
} catch (Exception e){
    testLog.info("Directory does not exists !!!\n"+e.fillInStackTrace().toString());;
}

The above code works seamlessly if I do Linux <-> Linux remote calls and validate the directory but with Linux <-> Windows I am encountering this issue.

Since mksnt is installed, if I go to the directory and do "pwd" - it prints "C:/abc/xyz"

I am not clear if Jsch is not able to handle or recognize the paths due to mksnt installed. Could anybody please share any solution or provide some pointer that may help me to resolve this.

PS: I cannot install cygwin or any other tool. This is the env. provided to me and I need to make remote calls from Linux host via Jsch utility only.

palkarrohan
  • 459
  • 1
  • 4
  • 16

2 Answers2

2
C:/abc/xyz

The SFTP protocol uses a unix-like naming scheme for file pathnames, regardless of the SFTP server's operating system. In the SFTP naming scheme, absolute pathnames begin with "/". A name beginning with "C" would reference a file in the SFTP session's working directory.

In other words, a Windows-based SFTP server might not interpret this pathname the way you expect it to. You should use an interactive SFTP client to log into the Windows SFTP server, locate the files and/or directories that you're interested in, and determine the correct path to use to access them through SFTP.

If the Windows SFTP server is running the Cygwin OpenSSH SFTP server, I believe the correct path would be something like "/cygdrive/c/abc/xyz".

Kenster
  • 23,465
  • 21
  • 80
  • 106
1

I have faced the same issue in the past and I have solved using the following code:

String remoteFolder = "C:\temp\test"
remoteFolder = "/" + remoteFolder.replace("\\", "/");

With this JSCH can detect if the remote path exists or not. This is only required in Windows.