Folder does not exists when changing directory using jcraft.jsch

user1261620

I'm running on a Linux machine a Java program that uses jcraft.jsch library to connect to an external sftp server. The code looks like:

JSch jsch = new JSch();
Session session = null;
Channel channel = null;  
ChannelSftp c = null;

session = jsch.getSession(ftpUserName, ftpHost, ftpPort);
session.setPassword(ftpPassword);

channel = session.openChannel("sftp");
channel.connect();
c = (ChannelSftp)channel;

fn = c.ls("/Inbox");
c.cd("/Inbox");  //-- this line throws an error

For some reason when I run the change directory command "c.cd" I get:

4: Folder not found: /drwxr-x--- 2 ftpadmin ftpadmin        0 Jan 01 1970 /Inbox

It is weird because the listing (c.ls) of that folder does not throws an exception.

Furthermore, if I lftp from the command line from the same Linux server I can cd without any problems.

enter image description here

The stacktrace points to a _stat method inside the cd method.

    at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2108)
    at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:1676)
    at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:290)
    at BW_Utilities.ftp.test.testFtpJsch(test.java:81)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

The folder structure of the remote site looks like the following when I connect using Filezilla from my desktop:

enter image description here

I just executed the same Java code on my windows desktop machine and the cd command worked. (Windows machine runs JDK 1.6.0_29 while the Linux server runs JRE 1.6.0.27)

Does jsch relies on some other library at the OS level at the client side?

Any idea how to proceed to troubleshoot this problem?

important UPDATE

I was able to reproduce the error on my dev machine. It got to do with jsch versions being used. The linux server is using jsch-0.1.31 while the dev machine uses jsch-0.1.52. It seems that whatever is causing the error is already solved in version 0.1.52. Wooot! Wooot! Finally!

Thanks

user1261620

Upgrading to jsch version 0.1.52 fixes the issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Connection issue using SFTP and JSch: com.jcraft.jsch.JSchException

From Dev

com.jcraft.jsch.JSchException: channel is not opened when opening a channel in jsch

From Dev

Does file directory/folder your code is in matter when using python3 modules ? I had an Issue

From Dev

checking if a folder exists in certain directory

From Dev

Bash:cd:No such folder or directory , but it exists

From Dev

com.jcraft.jsch.JSchException: verify: false

From Java

"Invalid privatekey" when using JSch

From Dev

"Invalid privatekey" when using JSch

From Dev

Using `os.path.exists` when the folder name has a space in it?

From Dev

Options for changing the directory index when using GitHub Pages

From Dev

mvc .htaccess disable changing url if directory exists

From Dev

AndroidStudio SDK directory does not exists

From Dev

Copying a source directory using the command cp -rsf when target directory exists

From Dev

com.jcraft.jsch.JSchException: Auth fail error

From Dev

com.jcraft.jsch.JSchException: Auth fail error

From Dev

com.jcraft.jsch.JSchException: failed to send sftp request

From Dev

Redirect to directory if directory exists using htaccess

From Dev

How can I recursively FTP a directory structure using Jsch?

From Dev

Check if folder exists does not work as expected

From Dev

Why url.exists returns FALSE when the URL does exists using RCurl?

From Dev

Jsch connection with private key fails with com.jcraft.jsch.JSchException: Auth fail error

From Dev

Jsch connection with private key fails with com.jcraft.jsch.JSchException: Auth fail error

From Dev

Optional statement to check when folder exists or not

From Dev

saltstack: creating directory only if does not exists

From Dev

When an API created in publisher portal, where does the api definition created (in wso2 folder directory)?

From Dev

Unable to search for directory using isdir when folder name had on numeric using Python

From Dev

Problem when changing permissions of a folder in a NTFS filesystem

From Java

FtpWebRequest returning "550 File unavailable (e.g. file not found, no access)" when using ListDirectoryDetails for a directory that exists

From Dev

When using SSH is it possible to prevent password authentication only if a certificate exists in the user's home directory?

Related Related

  1. 1

    Connection issue using SFTP and JSch: com.jcraft.jsch.JSchException

  2. 2

    com.jcraft.jsch.JSchException: channel is not opened when opening a channel in jsch

  3. 3

    Does file directory/folder your code is in matter when using python3 modules ? I had an Issue

  4. 4

    checking if a folder exists in certain directory

  5. 5

    Bash:cd:No such folder or directory , but it exists

  6. 6

    com.jcraft.jsch.JSchException: verify: false

  7. 7

    "Invalid privatekey" when using JSch

  8. 8

    "Invalid privatekey" when using JSch

  9. 9

    Using `os.path.exists` when the folder name has a space in it?

  10. 10

    Options for changing the directory index when using GitHub Pages

  11. 11

    mvc .htaccess disable changing url if directory exists

  12. 12

    AndroidStudio SDK directory does not exists

  13. 13

    Copying a source directory using the command cp -rsf when target directory exists

  14. 14

    com.jcraft.jsch.JSchException: Auth fail error

  15. 15

    com.jcraft.jsch.JSchException: Auth fail error

  16. 16

    com.jcraft.jsch.JSchException: failed to send sftp request

  17. 17

    Redirect to directory if directory exists using htaccess

  18. 18

    How can I recursively FTP a directory structure using Jsch?

  19. 19

    Check if folder exists does not work as expected

  20. 20

    Why url.exists returns FALSE when the URL does exists using RCurl?

  21. 21

    Jsch connection with private key fails with com.jcraft.jsch.JSchException: Auth fail error

  22. 22

    Jsch connection with private key fails with com.jcraft.jsch.JSchException: Auth fail error

  23. 23

    Optional statement to check when folder exists or not

  24. 24

    saltstack: creating directory only if does not exists

  25. 25

    When an API created in publisher portal, where does the api definition created (in wso2 folder directory)?

  26. 26

    Unable to search for directory using isdir when folder name had on numeric using Python

  27. 27

    Problem when changing permissions of a folder in a NTFS filesystem

  28. 28

    FtpWebRequest returning "550 File unavailable (e.g. file not found, no access)" when using ListDirectoryDetails for a directory that exists

  29. 29

    When using SSH is it possible to prevent password authentication only if a certificate exists in the user's home directory?

HotTag

Archive