JAVA下载远程Linux服务器的文件
2014-08-05 18:15
399 查看
<h1><span style="background-color: rgb(255, 255, 255);">RemoteAccessData.java</span></h1>
package com.yzj.demo; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.log4j.Logger; import com.yzj.log.LogFactory; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileInputStream; import jcifs.smb.SmbFileOutputStream; public class RemoteAccessData { private static Logger logger = LogFactory.getInstance(RemoteAccessData.class); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { smbGet("smb://username:password@11.132.3.13/prlife_ls_yanshou1_image/001/2013/12/05/10/00000053085901001/1/00000053085901001001.tif", "D:/download"); } /** * 路径格式:smb://192.168.75.204/test/新建 文本文档.txt * smb://username:password@192.168.0.77/test * @param remoteUrl * 远程路径 * @param localDir * 要写入的本地路径 */ public static void smbGet(String remoteUrl, String localDir) { InputStream in = null; OutputStream out = null; try { SmbFile remoteFile = new SmbFile(remoteUrl); if (remoteFile != null && remoteFile.exists()) { String fileName = remoteFile.getName(); File localFile = new File(localDir + File.separator + fileName); in = new BufferedInputStream(new SmbFileInputStream(remoteFile)); out = new BufferedOutputStream(new FileOutputStream(localFile)); byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); buffer = new byte[1024]; } } else { // 文件不存在 logger.info(remoteUrl + " 文件不存在!"); } } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); out = null; } catch (IOException e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * 向共享目录上传文件 * @param remoteUrl * @param localFilePath */ public static void smbPut(String remoteUrl, String localFilePath) { InputStream in = null; OutputStream out = null; try { File localFile = new File(localFilePath); String fileName = localFile.getName(); SmbFile remoteFile = new SmbFile(remoteUrl + "/" + fileName); in = new BufferedInputStream(new FileInputStream(localFile)); out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile)); byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); buffer = new byte[1024]; } } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); out = null; } catch (IOException e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
RemoteAccessData.java与jcifs-1.3.14.jar下载
Java下载上传远程Linux服务器文件.rar相关文章推荐
- Java利用ssh协议实现从远程Linux服务器下载文件和文件夹
- java使用Jsch实现远程操作linux服务器进行文件上传、下载,删除和显示目录信息
- [Java]远程下载文件并读取实例方法
- JAVA远程下载文件 总结 思路~~Myself
- Java远程连接操作linux服务器,scp获取文件
- java下载远程文件到本地
- Java实现文件远程上传和下载
- java远程文件下载,支持文件断点续传
- 使用ganymed-ssh2-build.jar来操作linux服务器(上传、下载文件,远程创建目录,远程删除文件等等)
- Java实现远程HDFS的文件操作(新建、上传、下载、删除)
- java下载远程服务器中以中文命名的文件
- 用java程序下载远程资源文件
- 通过SecureCRT下载远程Linux服务器上的文件到本地Windows
- 通过SecureCRT下载远程Linux服务器上的文件到本地Windows
- Java 通过SMB服务远程下载文件及zip包中的文件
- [Java]远程下载文件并读取实例方法
- java下载远程http地址的图片文件到本地-自动处理图片是否经过服务器gzip压缩的问题
- java 通过SSH方式连接远程主机并上传和下载文件
- 从远程Linux服务器下载文件到windows
- 通过SecureCRT工具从远程Linux服务器下载文件到本地Windows