首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Java-应用程序访问NFS-共享

从Java-应用程序访问NFS-共享
EN

Stack Overflow用户
提问于 2017-01-19 12:04:06
回答 2查看 11.6K关注 0票数 4

我正在尝试从CentOS应用程序中访问6.3系统上的NFS共享。我尝试过以下库,但两者都无法工作:

YaNFS

尝试用YaNFS访问NFS共享时,我遇到了一个带有ErrorCode 10001 (NFSERR_BADHANDLE)的NfsException。有时异常的文本会写成“陈旧的NFS文件句柄”。我的YaNFS代码是:

代码语言:javascript
复制
    public static void main(String[] args) {
    XFile xf = new XFile("nfs://192.168.1.10/nfs-share");

    nfsXFileExtensionAccessor nfsx =
        (nfsXFileExtensionAccessor)xf.getExtensionAccessor();

        if (! nfsx.loginPCNFSD("192.168.1.10", "rpx-nfs-user", "Test123!")) {
             System.out.println("login failed");
             return;
        }

        if (xf.canRead())
             System.out.println("Read permission OK");
        else
             System.out.println("No Read permission");

}

nfs-client-java

尝试用"nfs-client-java“初始化Nfs3对象时,我得到了如下所示的MountException:

代码语言:javascript
复制
com.emc.ecs.nfsclient.mount.MountException: mount failure, 
    server: 192.168.1.205, 
    export: /home/share, 
    nfs version: 3, 
    returned state: 13
at com.emc.ecs.nfsclient.nfs.nfs3.Nfs3.lookupRootHandle(Nfs3.java:359)

关于这一点,第13号州表示拒绝批准。

我可以通过挂载此共享从另一个CentOS-系统(授权访问此文件夹uid和gid)和Windows-系统(授权访问此文件夹登录和密码)访问此共享。

有没有人已经解决了这个问题?或者有人能帮我走得更远?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-01-08 08:55:39

通过在共享上启用CIFS协议并使用旧的JCIFS实现来传输数据,解决了这个问题。

票数 1
EN

Stack Overflow用户

发布于 2017-01-21 03:37:39

因此,您在注释中指出,需要特定用户的优先级才能访问文件,因此出现了“权限拒绝”错误。在YaNFS中,您需要查看nfsXFileExtensionAccessor才能发送用户名和密码,以便获得权限。下面是我从这个页面中提取的一个例子:https://docs.oracle.com/cd/E19455-01/806-1067/6jacl3e6g/index.html

代码语言:javascript
复制
import java.io.*;
import com.sun.xfile.*;
import com.sun.nfs.*;

public class nfslogin {

     public static void main(String av[])
     {
          try {
               XFile xf = new XFile(av[0]);
               com.sun.nfsXFileExtensionAccessor nfsx =
               (com.sun.nfsXFileExtensionAccessor)xf.getExtensionAccessor();

               if (! nfsx.loginPCNFSD("pcnfsdsrv", "bob", "-passwd-")) {
                    System.out.println("login failed");
                    return;
               }

               if (xf.canRead())
                    System.out.println("Read permission OK");
               else
                    System.out.println("No Read permission");

          } catch (Exception e) {
            System.out.println(e.toString());
            e.printStackTrace(System.out);
          }
     }
}

编辑

不,我认为您不应该在登录操作之前调用bind()。来自github上的XFile源代码

代码语言:javascript
复制
 /*
 * Check that the file is open.
 * The open() method must be called before
 * any other methods in the Accessor.
 * This makes it easier for Accessors to
 * centralize initialization code in one place.
 */
private boolean bind() {
    if (bound)
        return true;

    bound = xfa.open(this, false, false);

    return bound;
}

由于bind()函数试图打开文件,它将始终失败,直到您进行身份验证。然后考虑一下来自github上的XFileExtensionAccessor代码的代码

代码语言:javascript
复制
/**
 * Sets the user's RPC credential from Login name and password.
 *
 * Every NFS request includes a "credential" that identifies the user.
 * An AUTH_SYS credential includes the user's UID and GID values.
 * These are determined from the user's login name (and password)
 * by the PCNFSD service that must be available on a local server.
 * Once the credential is set, it is assigned globally to all
 * future NFS XFile objects.
 * <p>
 * If this method is not called, a default credential is assigned
 * with a UID and GID of "nobody".
 *
 * @param  <code>host</code> The name of the host that runs the PCNFSD service.
 *   This does not have to be an NFS server.
 * @param <code>username</code> The user's login name.
 * @param <code>password</code> The user's password.
 *   This is obscured before transmission to the PCNFSD server.
 * @return true if the login succeeded, false otherwise.
 */
public boolean loginPCNFSD(String host, String username, String password) {
    return NfsConnect.getCred().fetchCred(host, username, password);
}

因此,loginPCNFSD()函数将全局设置XFile系统的凭据,直到您注销或使用新登录。在调用XFile.Bind()之前一定要调用它;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41741365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档