最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何在Android 中實現(xiàn)scp操作

 更新時間:2021年03月17日 14:24:42   投稿:yxs  
這篇文章主要介紹了如何在Android 中實現(xiàn)scp操作,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下

本文簡單介紹用SSH庫ganymed-ssh2在Android中實現(xiàn)scp操作。

SSH

SSH是專為遠(yuǎn)程登錄會話和其他網(wǎng)絡(luò)服務(wù)提供安全性的協(xié)議,簡單的說就是一種網(wǎng)絡(luò)協(xié)議。是linux的標(biāo)準(zhǔn)配置。用于linux設(shè)備之間的通訊。

SCP

SCP是一種基于SSH完成加密拷貝文件的協(xié)議。使用SSH進(jìn)行身份認(rèn)證確保數(shù)據(jù)傳輸?shù)恼鎸嵭院涂煽啃浴?/p>

SCP默認(rèn)通過TCP端口22運行

SCP程序常用語法:

// 復(fù)制文件到主機
scp SourceFile user@host:directory/TargetFile


// 從主機復(fù)制文件
scp user@host:directory/SourceFile TargetFile
scp -r user@host:directory/SourceFolder TargetFolder
// 從主機復(fù)制文件
scp user@host:directory/SourceFile TargetFile
scp -r user@host:directory/SourceFolder TargetFolder

SFTP

SFTP也是基于SSH安全文件傳輸協(xié)議。不同于基于FTP,FTP基于Tcp使用明文傳輸用戶信息。安全性較差。

Android中使用SCP

  • 下載ganymed-ssh2 jar包
<!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 -->
<dependency>
  <groupId>ch.ethz.ganymed</groupId>
  <artifactId>ganymed-ssh2</artifactId>
  <version>build210</version>
</dependency>

官方下載地址 http://www.ganymed.ethz.ch/ssh2/

public class Scp {

  private volatile static Scp scpInstance;

  private String user;
  private String pass;
  private String host;
  private Connection connection;
  private SCPClient scpClient;
  private Boolean isAuthed;

  private Scp(String user, String pass, String host){
    this.user = user;
    this.pass = pass;
    this.host = host;
  }

  public static Scp getScpUtilsInstance(String user, String pass, String host){

    if(scpInstance == null) {
      synchronized(Scp.class) {
        if(scpInstance == null) {
          scpInstance = new Scp(user,pass,host);
        }
      }
    }
    return scpInstance;
  }


  public void connect(){
    connection = new Connection(host);
    try {
      connection.connect();
      isAuthed = connection.authenticateWithPassword(user,pass);
      // scp 連接
      scpClient = connection.createSCPClient();
    } catch (IOException e) {
      e.printStackTrace();
      close();
    }
  }

  public void close(){
    connection.close();
    sftPv3Client.close();
  }

  public boolean getIsAuthed(){
    return isAuthed;
  }

  // 拷貝文件到服務(wù)器
  public void putFile(String filePath,String aimPath){
    try {
      if(scpClient != null){
        scpClient.put(filePath,aimPath);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

 

}
Scp scp = Scp.getScpUtilsInstance("root","psd","192.168.199.3");
              scp.connect();
              if(scp.getIsAuthed()){
                for(int i = 0;i<data.getLayers();i++){
                  scp.putFile(SlcParser.pngDirectory+"/"+i+".png","/home");
                }
              }

SFTP 刪除文件

  private SFTPv3Client sftPv3Client;
  
  sftPv3Client = new SFTPv3Client(connection);

  public void rmFile(String filePath){
      try {
        if(sftPv3Client != null){
          sftPv3Client.rm(filePath);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }


Scp scp = Scp.getScpUtilsInstance("root","psd","192.168.199.3");
        scp.connect();
        if(scp.getIsAuthed()){
          for(int i = 0;i<10;i++){
            scp.rmFile("/home/"+i+".png");
          }
        }

以上就是如何在Android 中實現(xiàn)scp操作的詳細(xì)內(nèi)容,更多關(guān)于在Android 中實現(xiàn)scp操作的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

开化县| 南安市| 乳山市| 新绛县| 吴桥县| 万宁市| 江华| 原阳县| 丹阳市| 泸水县| 顺平县| 昌图县| 大竹县| 广西| 望江县| 上饶县| 荣昌县| 蛟河市| 长垣县| 霸州市| 福清市| 北票市| 安新县| 宁夏| 阜宁县| 潜山县| 崇文区| 芮城县| 清水县| 济阳县| 巴楚县| 电白县| 平阴县| 东山县| 松滋市| 县级市| 老河口市| 宣恩县| 牟定县| 乐安县| 民丰县|