| | |
| | | import java.io.IOException;
|
| | | import java.io.OutputStream;
|
| | | import java.net.Socket;
|
| | | import java.util.Date;
|
| | | import java.util.zip.ZipEntry;
|
| | | import java.util.zip.ZipOutputStream;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.config.AppConfig;
|
| | |
|
| | | public class HzipSocket{
|
| | | public static String targetip = "118.89.139.230"; //目标ip地址
|
| | | //public static String targetip = "118.89.139.230"; //目标ip地址
|
| | | //public static String targetip = "192.168.7.123"; //目标ip地址
|
| | | public static int targetport = 10100; //目标端口号
|
| | | private AppConfig cfg;
|
| | | |
| | | public HzipSocket(AppConfig cfg) {
|
| | | this.cfg = cfg;
|
| | | //System.err.println(cfg.getSourceSQLServerIp()+"########");
|
| | | }
|
| | |
|
| | | public void init(String filepath) {
|
| | | Socket s = null;
|
| | | try {
|
| | | Socket s = new Socket(targetip,10100);
|
| | | s = new Socket(cfg.getSourceSQLServerIp(),10100);
|
| | | //要发送出去的文件夹.请注意在不同操作系统上,表示方法可能不一样。
|
| | | File file =new File(filepath);
|
| | | OutputStream os=s.getOutputStream();
|
| | | ZipOutputStream gout=new ZipOutputStream(os);
|
| | | byte[] b=new byte[1024];
|
| | | zipEntry(file, gout,b);
|
| | | s.close();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | System.out.println(cfg.getSourceSQLServerIp()+"远程备份数据库失败"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
| | | } finally {
|
| | | if(null != s) {
|
| | | try {
|
| | | s.close();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | } |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | |
|
| | | public static void main(String[] args) {
|
| | | HzipSocket h = new HzipSocket();
|
| | | AppConfig cfg = new AppConfig();
|
| | | HzipSocket h = new HzipSocket(cfg);
|
| | | h.init("d:/temp");
|
| | | }
|
| | | }
|