共享文件下载--SMB

import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
import java.io.*;

/**
 * need seven parameters
 * account is used to access share folder
 * password is used to access share folder
 * ip specifies host in which share folder locates
 * shareDir is the path of share folder
 * file specifies the file supposed to be downloaded.
 * localDir specifies the local directory for preserving files downloaded.
 * localFile specifies the file name for downloaded files.
 */
public class ShareFileDownload {
   
    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 {
                String connStr = "smb://" + account + ":" + password + "@" + ip + "/" + shareDir + "/" + file ;
                System.out.println(connStr);
                SmbFile smbFile = new SmbFile(connStr);
                //"smb://pz:pz521@111.111.111.111/share/1.txt");
               
                int length = 1024*1024;
   
                SmbFileInputStream in = new SmbFileInputStream(smbFile);
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(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、付费专栏及课程。

余额充值