您的位置:首页 > 运维架构 > Linux

Windows做共享存储mount到Linux系统使用ftp工具上传与使用java程序上传文件

2018-02-22 15:38 1146 查看

Windows Server 2008 r2 FTP环境搭建

参照: https://jingyan.baidu.com/article/00a07f38550f2482d028dc13.html https://jingyan.baidu.com/article/0a52e3f4230067bf63ed7268.html
[b]Linux系统mount Windows 共享目录[/b]1、在Windows 上设置一个共享目录
如:将d:\_disk设置为共享目录
2、在Windows 上创建一个用户, 如tommy, 密码111111
3、将tommy 用户加入到共享目录d:\redhat_disk的访问组中,并设定tommy 对该共享目录有完全控制权限(读、写)
4、在Linux 下安装samba-client 客户端
# yum install samba-client
5、安装cifs-utils 软件包
# yum install cifs-utils
6、在Linux 下创建一个挂载点
# mkdir /mnt/Windows
7、挂载Windows 上的共享目录d:\redhat_disk到Linux 下的/mnt/Windows目录下

# mount -t cifs -o username=tommy,password=123456,rw,dir_mode=0777,file_mode=0777 //192.168.66.128/redhat_disk /mnt/Windows
rw,dir_mode=0777,file_mode=0777这些是设置文件夹权限,不然权限是0755,写不进去东西
8、如果挂载成功,则可以进入/mnt/Windows下,新建一个文件,看看Windows 上能否看见
9、在/etc/fstab文件中,加入该共享目录的挂载信息
//192.168.1.123/redhat_disk /mnt/Windows cifs username=tommy,password=123456, rw,dir_mode=0777,file_mode=0777
10、到此为止,Windows 上的共享目录//192.168.66.128/redhat_disk就被成功挂载到了Linux 上面了,并且Linux 重启后,会自动挂载该目录到/mnt/Windows目录下
11.开机启动就挂载文件夹
  在/etc/fstab文件中添加下列代码
  //192.168.121.122/share /mnt/share cifs username=xxx,password=passwd 0 0

java程序上传
public void uploadfileToRemote() {
        InputStream in = null;
        OutputStream out = null;

        try {
            File localFile = new File("H:/dianying.mkv/");
            String remotePhotoUrl = "smb://admin:admin@192.168.66.128/redhat_disk";
            SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS_");
           SmbFile remoteFile = new SmbFile(remotePhotoUrl + "/" + fmt.format(new Date()) + localFile.getName());
            remoteFile.connect(); // 尝试连接

            in = new BufferedInputStream(new FileInputStream(localFile));
            out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile));
            byte[] buffer = new byte[4096];
            int len = 0; // 读取长度
            while ((len = in.read(buffer, 0, buffer.length)) != -1) {
                out.write(buffer, 0, len);
            }
            out.flush(); // 刷新缓冲的输出流

        } catch (Exception e) {
             String msg = "发生错误:" + e.getLocalizedMessage();  
             System.out.println(msg);  
        }finally {
            try {  
                if(out != null) {  
                    out.close();  
                }  
                if(in != null) {  
                    in.close();  
                }  
            }  catch (Exception e) {
                
            }  
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐