当前位置:网站首页>使用SSH
使用SSH
2022-07-04 17:10:00 【用户7741497】
%Net.SSH
软件包支持SSH
(安全外壳)通信。本主题简要介绍此包中的类。
创建SSH会话
%Net.SSH.Session
表示SSH
会话。要使用此类,请执行以下操作:
- 创建类的实例。
- 使用
Connect()
实例方法连接到服务器。 - 使用
AuthenticateWithKeyPair()
或AuthenticateWithUsername()
向服务器验证身份。 - 使用
%Net.SSH.Session
的其他方法执行进出远程系统的单个文件的SCP(安全复制)操作、执行远程命令、传输TCP通信或执行SFTP操作。
例如,使用SFTP
将会话用于SFTP
操作。此方法通过引用返回可用于SFTP
操作的%Net.SSH.SFTP
实例。
重要提示:有关可以使用这些类的受支持平台的信息,请参阅%Net.SSH.Session
和%Net.SSH.SFTP
的类参考。
示例:通过SFTP列出文件
以下方法显示了如何通过SFTP
在服务器上写入文件列表:
Method SFTPDir(ftpserver, username, password) As %Status
{
set ssh = ##class(%Net.SSH.Session).%New()
do ssh.Connect(ftpserver)
do ssh.AuthenticateWithUsername(username,password)
//open an SFTP session and get that returned by reference
do ssh.OpenSFTP(.sftp)
//get a list of files
do sftp.Dir(".",.files)
set i=$ORDER(files(""))
while i'="" {
write $listget(files(i),1),!
set i=$ORDER(files(i))
}
quit $$$OK
}
其他示例
/// Demonstrates the execution of a remote command (by default, uname -a).
ClassMethod TestExecute(host As %String, username As %String, password As %String, command As %String = "uname -a", pTimeout As %Integer = -1) As %Status
{
Set s = ##class(%Net.SSH.Session).%New()
Set sc = s.Connect(host)
Quit:$$$ISERR(sc) sc
If pTimeout'=-1 {
Set sc = s.SetTimeout(pTimeout)
Quit:$$$ISERR(sc) sc
}
Set sc = s.AuthenticateWithUsername(username,password)
Quit:$$$ISERR(sc) sc
Set sc = s.Execute(command,.tDevice)
Quit:$$$ISERR(sc) sc
Set $ZT="Trap"
For {
Use tDevice
Read X
Use $P
If X'[$C(13) {
For i=1:1:$L(X,$C(10)) Write $P(X,$C(10),i),!
} Else {
Write X
}
}
Exit
Use $P
Close tDevice
Quit sc
Trap
Set sc = $S($ZE["<READ>":$$$OK,1:$$$ERROR($$$CacheError,$ZE))
Goto Exit
}
/// Demonstrates the use of port forwarding to whatismyipaddress.com via the remote SSH server.
ClassMethod TestForwardPort(host As %String, username As %String, password As %String, remotehost As %String = "whatismyipaddress.com", remoteport As %Integer = 80) As %Status
{
Set s = ##class(%Net.SSH.Session).%New()
Set sc = s.Connect(host)
Quit:$$$ISERR(sc) sc
Set sc = s.AuthenticateWithUsername(username,password)
Quit:$$$ISERR(sc) sc
Set sc = s.ForwardPort(remotehost,remoteport,.tDevice)
Quit:$$$ISERR(sc) sc
Set $ZT="Trap"
Use tDevice
Write "GET / HTTP/1.0"_$C(13,10,13,10)
Write *-3 // Flush
// Now the response
For {
Use tDevice
Read X
Use $P
If X'[$C(13) {
For i=1:1:$L(X,$C(10)) Write $P(X,$C(10),i),!
} Else {
Write X
}
}
Exit
Use $P
Close tDevice
Quit sc
Trap
Set sc = $S($ZE["<READ>":$$$OK,1:$$$ERROR($$$CacheError,$ZE))
Goto Exit
}
边栏推荐
- Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
- ITSS运维能力成熟度分级详解|一文搞清ITSS证书
- How to download files using WGet and curl
- Load test practice of pingcode performance test
- Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
- Journal des problèmes de brosse à boutons de force / day6 / 6.28
- MySQL common add, delete, modify and query operations (crud)
- [209] go language learning ideas
- 2022年字节跳动日常实习面经(抖音)
- Li Kou brush question diary /day6/6.28
猜你喜欢
Scala basic tutorial -- 15 -- recursion
The block:usdd has strong growth momentum
Once the "king of color TV", he sold pork before delisting
力扣刷题日记/day5/2022.6.27
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Halcon template matching
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
中国农科院基因组所汪鸿儒课题组诚邀加入
Wireshark抓包TLS协议栏显示版本不一致问题
能源行业的数字化“新”运维
随机推荐
I wrote a learning and practice tutorial for beginners!
Load test practice of pingcode performance test
SIGMOD’22 HiEngine论文解读
删除二叉搜索树中的节点附图详解
Detailed explanation of the maturity classification of ITSS operation and maintenance capability | one article clarifies the ITSS certificate
Numpy 的仿制 2
被忽视的问题:测试环境配置管理
The controversial line of energy replenishment: will fast charging lead to reunification?
Scala basic tutorial -- 17 -- Collection
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
Machine learning concept drift detection method (Apria)
Scala basic tutorial -- 14 -- implicit conversion
Why are some online concerts always weird?
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Li Kou brush question diary /day6/6.28
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Wireshark抓包TLS协议栏显示版本不一致问题
力扣刷题日记/day6/6.28
力扣刷题日记/day7/2022.6.29