共享文件上传--SMB

来源:互联网 发布:淘宝客服常见刁蛮问题 编辑:程序博客网 时间:2024/05/25 23:26

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.");
        }
       
    }
}
 

原创粉丝点击