4

ローカル マシンから Windows サーバーの共有フォルダーにファイルをコピーしようとしています。これは私が使用した機能です。

public static void copyFileUsingJcifs(final String domain, final String userName, final String password, final String sourcePath, final String destinationPath) throws IOException {
    final NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, userName, password);
    final SmbFile sFile = new SmbFile(destinationPath, auth);
    final SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(sFile);
    final FileInputStream fileInputStream = new FileInputStream(new File(
            sourcePath));

    final byte[] buf = new byte[16384];
    int len;
    while ((len = fileInputStream.read(buf)) > 0) {
        smbFileOutputStream.write(buf, 0, len);
    }
    fileInputStream.close();
    smbFileOutputStream.close();
}

この回答を試しましたが、うまくいきませんでした。通常のコピー(コピーと貼り付け)を行うと、 25MBのファイルで最大8分しかかかりません。しかし、この関数を使用して Java プログラムを使用すると、20 分以上かかります。このコピーを高速化するにはどうすればよいですか? 前もって感謝します。

4

6 に答える 6

2

それでも遅い場合は、高度に最適化されたこの関数を試してから、コードのバッファ サイズを増やしてください。私の場合、48MB のファイルをコピーする時間が 10 分から 1 分に短縮されました。

public static boolean createCopyOnNetwork(String domain,String username,String password,String src, String dest) throws Exception
{
    //FileInputStream in = null;
    SmbFileOutputStream out = null;
     BufferedInputStream inBuf = null;
    try{
        //jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords","true");
        NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication(domain,username,password); // replace with actual values  
        SmbFile file = new SmbFile(dest, authentication); // note the different format
        //in = new FileInputStream(src);
          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;
}
于 2015-08-27T05:21:41.197 に答える
2

私が気付いたのは、jCIFS が読み取るすべてのチャンク、つまり、バッファに読み取られる各チャンクに対して「何か」(jcifs.smb.SmbTransport.checkStatus(..) について) を行うことです。つまり、実際の問題はまだ存在しますが、バッファサイズを大きくすると実際に速度が向上する可能性がありますが、全体の時間への影響が少ない1〜2回しか発生しません..

「jcifs.util.loglevel=3」を設定して、実際に何が問題なのかを調べると、非常に役立ちます..

私の場合、「jcifs.resolveOrder=DNS」が役に立たなかったため、最後に「jcifs.smb.client.dfs.disabled=false」を設定する必要がありました..

于 2015-10-28T15:12:02.963 に答える
2

それが他の人を助ける場合...私は同様の問題を抱えていましたが、別の方向でした(JCIFSを使用したWindowsへのコピーが遅い)。この問題は、追加することで解決されました

   -Djcifs.resolveOrder=DNS

物件一覧へ。( NetBIOS 名クエリ ブロードキャストを 255.255.255.255 に送信するための BCASTのデフォルトの組み込みが、膨大な遅延の原因でした。)

于 2013-09-16T21:33:25.493 に答える
1

私は同じ問題を抱えていました。-Djcifs.resolveOrder=DNS を試してみましたが、うまくいきませんでした。バッファサイズに関するいくつかのコメントを読んだ後、私は極端に行き、実際にそれを増やすことにしました. 転送速度は少なくとも 50mb/s である必要があることがわかっているので、それをバイトに変換してバッファとして設定すると、期待どおりに動作しました。

于 2014-06-30T20:21:08.533 に答える