java jcifs 创建文件夹,如何使用Java中的jcifs将文件从smb共享复制到本地驱动器?...

Could anybody help me to copy file from shared folder to local drive? My code is:

import jcifs.smb.NtlmPasswordAuthentication;

import jcifs.smb.SmbFile;

import jcifs.smb.SmbFileInputStream;

import jcifs.smb.SmbFileOutputStream;;

public class smb {

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

String urlToBackUpFile = "smb://ip/backup$/test.txt";

System.out.println("smb folder of source file" + urlToBackUpFile);

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "login", "pass");

SmbFile dir = new SmbFile(urlToBackUpFile, auth);

System.out.println(dir.getDate());

SmbFile dest = new SmbFile ("C:/SQLRESTORESTAGE/v2.bak");

dir.copyTo(dest);

}

}

File file is not copied. I received a message "Failed to connect to server", but the programm shows dir.getDate() (and file name, and lenght) of source file. So I think the problem with destination folder (C:/SQLRESTORESTAGE/). Also I have proviledges only for reading source file. Could you help me to cirrect the code or advise something? Thank you.

解决方案

maybe adding auth to the second file:

SmbFile dest = new SmbFile ("C:/SQLRESTORESTAGE/v2.bak",**auth**);

using SmbFile dest = new SmbFile ("C:/SQLRESTORESTAGE",auth).canWrite

you know if you have write permissions on the parent directory

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值