java - SmbFileInputStream 导致 SmbException : SMB URL Syntax?

标签 java smb jcifs

我正在尝试创建一个 SmbFileInputStream,指向一个在我的系统上确实存在的目录。我正在使用以下代码。每次,我都会在第三个 try-catch 中收到一个错误,向我显示下面的堆栈跟踪。我认为错误出在 SMB URL 的格式中。如果有人能帮助指出我在域、服务器和用户信息的配置中可能存在的错误,或者如何转义下面的特殊字符,我将不胜感激。

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import jcifs.smb.*;
import jcifs.*;

public class jcifsX {

    public static void main (String[] args){
        System.err.println("*********************************************************** loadWorkbookOrFail was ran");
        // create a new file input stream with the input file specified by fileName

        jcifs.Config.registerSmbURLHandler();


        NtlmPasswordAuthentication npa = null;
        try{
            npa = new NtlmPasswordAuthentication("myDomain","myUser","myPass");
            System.err.println("*********************************************************** NtlmPasswordAuthentication created successfully");
        } catch (Exception e) {
            System.err.println("*********************************************************** Failed to create NtlmPasswordAuthentication. Stack trace to follow");
            e.printStackTrace();
        }


        SmbFile smbf = null;
        try{
            smbf = new SmbFile("smb:" + "//myDomain;myUser:myPass@myServer/myShare/" + args, npa);
            System.err.println("*********************************************************** SmbFile successfully created");
            }
        catch (Exception e) {
            System.err.println("*********************************************************** Stack trace to follow");
            e.printStackTrace();
        }


        SmbFileInputStream sfin = null;
        try{
            sfin = new SmbFileInputStream(smbf);
            System.err.println("*********************************************************** SmbFileInputStream successfully initiated");
            throw new IllegalArgumentException("If you're seeing this, it looks like it worked");
            }
        catch (Exception e){
            System.err.println("*********************************************************** SmbFileInputStream failed: Stack trace to follow. args = " + args);
            e.printStackTrace();
        }
    }
}

我在运行时收到的堆栈跟踪看起来像

jcifs.smb.SmbException: The system cannot find the file specified.
    at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:563)
    at jcifs.smb.SmbTransport.send(SmbTransport.java:663)
    at jcifs.smb.SmbSession.send(SmbSession.java:238)
    at jcifs.smb.SmbTree.send(SmbTree.java:119)
    at jcifs.smb.SmbFile.send(SmbFile.java:775)
    at jcifs.smb.SmbFile.open0(SmbFile.java:989)
    at jcifs.smb.SmbFile.open(SmbFile.java:1006)
    at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
    at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
    at jcifsX.main(jcifsX.java:61)

提前感谢任何愿意花时间解决这个问题的人。非常感谢。

最佳答案

您使用了 "smb:"+ "//myDomain;myUser:myPass@myServer/myShare/"+ args。这将生成像这样的字符串 smb://myDomain;myUser:myPass@myServer/myShare/[Ljava.lang.String;@470ae2bf

所以像这样使用 "smb:"+ "//myDomain;myUser:myPass@myServer/myShare/"+ args[0]。使用适当的索引而不是 0。

关于java - SmbFileInputStream 导致 SmbException : SMB URL Syntax?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21344631/

相关文章:

java - 独立的 jenkins.war 与配置持久性?

java - 如何找到奇偶校验异常值 kata

java - 当之前的一些行在我自己的 Eclipse 编辑器中折叠时获取当前行

java - 递归函数StackOverflowError

java - SMBJ 和 DFS 和 "Nested Session"

macos - 符号链接(symbolic link)在共享到 Windows 或 Linux (smb) 时有效,但在共享到 Mac(afp 或 smb)时损坏

Python IOError : Not a gzipped file (Gzip and Blowfish Encrypt/Compress) 错误

java - 创建新的 SmbFileInput 时出现 NullpointerException

java - 性能:使用 JCIF 将文件复制到 Windows 网络非常慢

smb - 如何使用 JCIFS 将文件从 SMB 共享复制到不在域中的本地驱动器