91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 16KB
    文件類型: .java
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-14
  • 語言: Java
  • 標簽: 遠程讀寫??

資源簡介

主要實現的是登錄服務器操作服務器的中的文件數據,支持讀寫的操作。主要使用的方法getProperties是設置配置的login(參數一是訪問服務器的配置,參數二是設置讀還是寫)方法是讀寫連接服務器

資源截圖

代碼片段和文件信息

package?com.maxd.upload;

import?java.io.*;
import?java.util.ArrayList;
import?java.util.List;
import?java.util.Properties;
import?java.util.Scanner;
import?java.util.regex.Matcher;
import?java.util.regex.Pattern;

import?ch.ethz.ssh2.Connection;
import?ch.ethz.ssh2.SCPClient;
import?ch.ethz.ssh2.StreamGobbler;
import?com.jcraft.jsch.*;
import?com.maxd.utils.Config;

public?class?LoginServer?{
????/**
?????*?@param?ip??????????????服務器IP
?????*?@param?user????????????服務器用戶名
?????*?@param?pwd?????????????服務器密碼
?????*?@param?port????????????端口
?????*?@param?privateKeyPath??可為空
?????*?@param?passphrase??????可為空
?????*?@param?sourcePath??????本地文件路徑
?????*?@param?destinationPath?上傳路徑
?????*/
????private?static?void?downLoadFile(String?ip?String?user?String?pwd?String?port?String?privateKeyPath?String?passphrase?String?sourcePath?String?destinationPath)?{
????????doWrite(ip?user?pwd?port?privateKeyPath?passphrase?sourcePath?destinationPath);
????}

????/**
?????*?設置配置
?????*
?????*?@param?fileName
?????*?@return
?????*/
????public?static?Properties?getProperties(String?fileName)?{
????????Properties?properties?=?new?Properties();
????????properties.setProperty(“ip“?Config.hostname);
????????properties.setProperty(“user“?Config.username);
????????properties.setProperty(“pwd“?Config.password);
????????properties.setProperty(“port“?String.valueOf(Config.port));
????????properties.setProperty(“sourcePath“?Config.sourcePath?+?fileName);
????????properties.setProperty(“destinationPath“?Config.destinationPath);
????????return?properties;
????}

????/**
?????*?@param?properties
?????*?@param?isRead?????true表示讀取?false表示寫入
?????*/
????public?static?void?login(Properties?properties?boolean?isRead)?{
????????String?ip?=?properties.getProperty(“ip“);
????????String?user?=?properties.getProperty(“user“);
????????String?pwd?=?properties.getProperty(“pwd“);
????????String?port?=?properties.getProperty(“port“);
????????String?privateKeyPath?=?properties.getProperty(“privateKeyPath“);
????????String?passphrase?=?properties.getProperty(“passphrase“);
????????String?sourcePath?=?properties.getProperty(“sourcePath“);
????????String?destinationPath?=?properties.getProperty(“destinationPath“);
????????if?(!isRead)?{
????????????//寫入本地文件到遠程服務器
????????????doWrite(ip?user?pwd?port?privateKeyPath?passphrase?sourcePath?destinationPath);
????????}?else?{
????????????//讀取遠程文件到本地
????????????readConnect();
????????}
????}

????/**
?????*?@throws?IOException
?????*?@description?讀文件
?????*/
????public?static?String?readTxtFile(File?fileName)?throws?IOException?{
????????String?result?=?null;
????????FileReader?fileReader?=?null;
????????BufferedReader?bufferedReader?=?null;
????????fileReader?=?new?FileReader(fileName);
????????InputStreamReader?isr?=?new?InputStreamReader(new?FileInputStream(fileName)?“UTF-8“);
????????BufferedReader?bufferedReader1?=?new?BufferedReader(isr);

評論

共有 條評論

相關資源