共享文件上传--SMB

import java.io.*;

import jcifs.smb.SmbFileOutputStream;
import jcifs.smb.SmbFile;

public class ShareFileUpload {

    public static void main(String[] args) {
       
        if(args.length == 7){
           
            String account = args[0].trim();
            String password = args[1].trim() ;
            String ip = args[2].trim();
            String shareDir = args[3].trim() ;
            String file = args[4].trim() ;
            String localDir = args[5].trim();
            String localFile = args[6].trim();
           
            try {
                SmbFile smbFile = new SmbFile(
                    "smb://" + account + ":" + password + "@" + ip + "/" + shareDir + "/" + file);
                //"smb://zp:zp521@111.111.111.111/share/1.txt");
                int length = 1024*1024;
   
                SmbFileOutputStream out = new SmbFileOutputStream(smbFile);
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(localDir + "/" + localFile)));

                byte[] buffer = new byte[length];
                while ((in.read(buffer)) != -1) {
   
                    out.write(buffer);
                    buffer = new byte[length];
                }
               
                in.close();
                out.close();
               
            } catch (Exception e) {
               
                e.printStackTrace();
            }
        }else{
           
            System.out.println("Need seven parameters.");
        }
       
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值