当前位置:网站首页>使用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
}边栏推荐
- 字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
- Principle and application of ThreadLocal
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- 力扣刷题日记/day2/2022.6.24
- 力扣刷题日记/day8/7.1
- [mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
- Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
- Lua EmmyLua 注解详解
- NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
- 一直以为做报表只能用EXCEL和PPT,直到我看到了这套模板(附模板)
猜你喜欢

Li Kou brush question diary /day7/6.30

Scala basic tutorial -- 18 -- set (2)

Halcon模板匹配

蓝桥:合根植物

Torchdrug tutorial

Angry bird design based on unity

字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验

Wireshark抓包TLS协议栏显示版本不一致问题

输入的查询SQL语句,是如何执行的?
![[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation](/img/63/8d5f875b4409511628faf2914836d3.png)
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
随机推荐
6.26CF模拟赛E:价格最大化题解
力扣刷题日记/day5/2022.6.27
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
Scala基础教程--16--泛型
Load test practice of pingcode performance test
Digital "new" operation and maintenance of energy industry
2022 ByteDance daily practice experience (Tiktok)
线上MySQL的自增id用尽怎么办?
Lua emmylua annotation details
How to improve development quality
Scala基础教程--13--函数进阶
Angry bird design based on unity
Scala基础教程--20--Akka
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
【209】go语言的学习思想
大厂面试总结大全二
Thawte通配符SSL证书提供的类型有哪些
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
How is the entered query SQL statement executed?