使用JSch拒绝权限 [英] Permission denied using JSch

查看:227
本文介绍了使用JSch拒绝权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSch从sftp服务器检索一些文件,但是出现以下错误.

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)

这是代码:

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是具有以下值的属性:/user_files. 这两个文件夹(源文件夹和目标文件夹)都在Windows服务器上,并且所有特权都授予了任何用户.但是由于某种原因,它不允许我更改源(远程)服务器中的当前目录.

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

有什么主意吗?

更新:Sftp服务器是freeFTPd,使用sftp客户端(如Filezilla),我可以毫无问题地移动文件

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

推荐答案

/user_files可能是绝对路径.

尝试./user_files获取用户主目录的相对路径.

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

在Filezilla中,它是远程端上的C:\user_files吗?

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

这篇关于使用JSch拒绝权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆