jcifs.smb.SmbException:拒绝访问

时间:2017-11-29 16:09:19

标签: java

我有一个要求,我必须将文件从本地工作区复制到网络驱动器。我有所有工作凭据打开网络驱动器,看看,我正在使用JCIF方法来实现这一点但不幸的是,当我运行以下代码时,我获得访问被拒绝的异常

public static void main(String[] args) {
        File file = new File("D:\\sampletext.txt");
        try {
            createCopyOnNetwork("prestige", "sannayalap", "Ci**@***", "D:\\sampletext.txt", "smb://10.28.41.**//d$//CDSBatches//test"); 

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

    }

public static boolean createCopyOnNetwork(String domain,String username,String password,String src, String dest) throws Exception
    {
        SmbFileOutputStream out = null;
        BufferedInputStream inBuf = null;
        try{
            NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication(domain,username,password); // replace with actual values  
            SmbFile file = new SmbFile(dest, authentication); // note the different format
            inBuf = new BufferedInputStream(new FileInputStream(src));
            out = (SmbFileOutputStream)file.getOutputStream();
            byte[] buf = new byte[5242880];
            int len;
            while ((len = inBuf.read(buf)) > 0){
                out.write(buf, 0, len);
            }
        }
        catch(Exception ex)
        {
            throw ex;
        }
        finally{
            try{
                if(inBuf!=null)
                    inBuf.close();
                if(out!=null)
                    out.close();
            }
            catch(Exception ex)
            {}
        }
        System.out.print("\n File copied to destination");
        return true;
    }

当我运行时遇到此异常

jcifs.smb.SmbException: Access is denied.
    at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:563)
    at jcifs.smb.SmbTransport.send(SmbTransport.java:664)
    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:992)
    at jcifs.smb.SmbFile.open(SmbFile.java:1009)
    at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
    at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97)
    at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67)
    at jcifs.smb.SmbFile.getOutputStream(SmbFile.java:2856)
    at dev.copyFileRemote.createCopyOnNetwork(copyFileRemote.java:36)
    at dev.copyFileRemote.main(copyFileRemote.java:141)

如果有人知道如何将文件复制到网络驱动器,那么请帮忙。如果你知道任何其他方法来实现这一点,请建议你。

0 个答案:

没有答案