hierynomus / sshj

ssh, scp and sftp for java
Apache License 2.0
2.51k stars 601 forks source link

net.schmizz.sshj.sftp.SFTPException: No such file #435

Open sibiarunachalam opened 6 years ago

sibiarunachalam commented 6 years ago

sshj version: 0.21.0 Client: Linux SSH Server: Linux Or Windows (Tested in both OS) Code:

SSHClient sshClient = new SSHClient();
sshClient.addHostKeyVerifier("hostKeyVerifier");
sshClient.authPassword("foouser", "fooPassword");
sshClient.newSFTPClient().get("fooDir", "/home/baruser/temp");

Exception:

net.schmizz.sshj.sftp.SFTPException: No such file
    at net.schmizz.sshj.sftp.Response.error(Response.java:137)
    at net.schmizz.sshj.sftp.Response.ensurePacketTypeIs(Response.java:114)
    at net.schmizz.sshj.sftp.SFTPEngine.openDir(SFTPEngine.java:161)
    at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.downloadDir(SFTPFileTransfer.java:119)
    at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.download(SFTPFileTransfer.java:99)
    at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.access$300(SFTPFileTransfer.java:90)
    at net.schmizz.sshj.sftp.SFTPFileTransfer.download(SFTPFileTransfer.java:71)
    at net.schmizz.sshj.sftp.SFTPFileTransfer.download(SFTPFileTransfer.java:59)
    at net.schmizz.sshj.sftp.SFTPClient.get(SFTPClient.java:229)

Note: It works with SCPFileTransfer

sibiarunachalam commented 6 years ago

It looks purely SSH Server configuration problem. It worked in Windows after setting Mount Points in SSH Server

sibiarunachalam commented 6 years ago

But, I didn't get any clue for Linux. It throws same exception when I try to get files in "fooDir" from foouser's HOME dir I expect, sshj should get "fooDir" from user's home directory by default

hierynomus commented 6 years ago

I'm not sure I'm following you. Can you write a clear problem description?

duelinmarkers commented 5 years ago

Don't know whether this was @sibiarunachalam's issue, as the stack trace is slightly different, and I'm trying to get a regular file, not a directory, but I just worked through the following thing that sounds similar:

In debugging I found that both canonicalize and get internally result in an attempt to use the path /remote_file.txt—note the incorrect leading /.

Edit: I also confirmed that sftpClient.get("/somedir/remote_file.txt", "./local.txt") succeeds, but I didn't see a way to determine the canonical remote path programmatically.

net.schmizz.sshj.sftp.SFTPException: No such file

    at net.schmizz.sshj.sftp.Response.error(Response.java:137)
    at net.schmizz.sshj.sftp.Response.ensurePacketTypeIs(Response.java:114)
    at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:143)
    at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:149)
    at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:154)
    at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.downloadFile(SFTPFileTransfer.java:134)
    at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.download(SFTPFileTransfer.java:105)
    at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.access$300(SFTPFileTransfer.java:90)
    at net.schmizz.sshj.sftp.SFTPFileTransfer.download(SFTPFileTransfer.java:71)
    at net.schmizz.sshj.sftp.SFTPFileTransfer.download(SFTPFileTransfer.java:59)
    at net.schmizz.sshj.sftp.SFTPClient.get(SFTPClient.java:229)
hierynomus commented 5 years ago

Which version are you using?

duelinmarkers commented 5 years ago

com.hierynomus:sshj:0.26.0

Also, I found that ./remote_file.txt works, just not remote_file.txt.