Permission denied using JSch

匿名 (未验证) 提交于 2019-12-03 08:56:10

问题:

I'm trying to retrieve some files from sftp server using JSch but I'm getting the following error.

3: Permission denied at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2340) at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:342) at com.company.common.sftp.impl.managedFile.moveFiles(managedFile.java:712) 

Here is the code:

private List<String> moveFiles(String prefixFileName, String path) {     Session session = getSession();     Channel channel = connect(session);     ChannelSftp channelSftp = null;     try {         channelSftp = (ChannelSftp)channel;         channelSftp.cd(_workingDir);     ...     }     ...     finally {         channel.disconnect();         session.disconnect();     } }  public Session getSession() {                   Session session = null;     JSch jsch = new JSch();     session = jsch.getSession(_user,_server,_port);     session.setPassword(_password);     java.util.Properties config = new java.util.Properties();     config.put("StrictHostKeyChecking", _strictHostKeyChecking);     session.setConfig(config);     session.connect();     return session;  }  public static Channel connect(Session session) {   Channel channel = null;   channel = session.openChannel("sftp");   channel.connect();   return channel; } 

_workingDir is a property with the following value: /user_files. Both folders (source and destination) are on a Windows server and all the privileges was granted to any user. But for some reason it doesn't let me change the current directory in the source (remote) server.

Any idea?

UPDATE: The Sftp server is freeFTPd and using a sftp client (like Filezilla) I can move files without problems

回答1:

Probably /user_files is an absolute path.

Try ./user_files for a relative path to the user's home directory.

In Filezilla, it is C:\user_files on the remote side ?



回答2:

The same issue was encountered by me and verifying the followings fixed my issue:

  1. Path of the file we are trying to retrieve doesn't exist. So, please make sure that file actually exists under the directory that your application is accessing to retrieve the file.
  2. Make sure SFTP user that you are using in the application to make the connection is configured and active in SFTP.
  3. If above both points are valid in your scenario then try after rebooting the SFTP service.


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!