午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:18日期:2022-09-20 14:57:34

本文簡單介紹用SSH庫ganymed-ssh2在Android中實(shí)現(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ù)恼鎸?shí)性和可靠性。

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

SCP程序常用語法:

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

// 從主機(jī)復(fù)制文件scp user@host:directory/SourceFile TargetFilescp -r user@host:directory/SourceFolder TargetFolderSFTP

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');} }

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

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 中實(shí)現(xiàn)scp操作

以上就是如何在Android 中實(shí)現(xiàn)scp操作的詳細(xì)內(nèi)容,更多關(guān)于在Android 中實(shí)現(xiàn)scp操作的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 3d动漫精品啪啪一区二区免费 | 欧美精品v | 天天拍夜夜拍 | 天堂网视频在线 | 亚洲国产精品99久久久久久久久 | 少妇视频在线 | 久久成年人视频 | 不卡视频一区二区 | 男女免费视频网站 | 中文字幕亚洲视频 | 91久久综合亚洲鲁鲁五月天 | 精品一二三四区 | 日韩一级免费毛片 | 91最新网站| 夜夜爽影院 | av天天干 | 欧美性a视频 | 夜夜爽天天干 | 国产精品麻豆一区二区 | 欧美激情在线播放 | 成人黄色免费网址 | 97国产精品久久 | xxx综合网 | 国产又爽又黄网站 | 国产精品一二三区在线观看 | 亚洲成人精品一区二区 | 天天看av | 黄色片在线免费观看 | 最新精品国产 | 色婷婷国产精品免 | 九九热视频在线播放 | av性天堂网| 日本久久一区二区 | 天天做天天操 | 国产精品福利小视频 | 欧美激情视频在线 | 一区二区三区国产在线观看 | av色综合 | 久久综合影视 | 国产精品免费一区 | 久久调教|