当前位置:网站首页>Using SSH
Using SSH
2022-07-04 19:00:00 【User 7741497】
%Net.SSH
Package support SSH
( Safety enclosure ) signal communication . This topic briefly introduces the classes in this package .
establish SSH conversation
%Net.SSH.Session
Express SSH
conversation . To use this class , Do the following :
- Create an instance of a class .
- Use
Connect()
The instance method connects to the server . - Use
AuthenticateWithKeyPair()
orAuthenticateWithUsername()
Authenticate to the server . - Use
%Net.SSH.Session
Other methods of executing a single file in and out of a remote system SCP( Secure replication ) operation 、 Execute remote command 、 transmission TCP Communication or execution SFTP operation .
for example , Use SFTP
Use the session for SFTP
operation . This method returns by reference that can be used for SFTP
Operation of the %Net.SSH.SFTP
example .
Important note : Information about supported platforms that can use these classes , see also %Net.SSH.Session
and %Net.SSH.SFTP
Class reference for .
Example : adopt SFTP Lists the files
The following method shows how to pass SFTP
Write the file list on the server :
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
}
Other examples
/// 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
}
边栏推荐
- 利用策略模式优化if代码【策略模式】
- ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
- 被忽视的问题:测试环境配置管理
- 6.26CF模拟赛E:价格最大化题解
- 力扣刷题日记/day1/2022.6.23
- ThreadLocal原理与使用
- NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
- Scala基础教程--12--读写数据
- What if the self incrementing ID of online MySQL is exhausted?
- 线上MySQL的自增id用尽怎么办?
猜你喜欢
基于NCF的多模块协同实例
Li Kou brush question diary /day4/6.26
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
谷粒商城(一)
力扣刷题日记/day5/2022.6.27
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
Wireshark packet capturing TLS protocol bar displays version inconsistency
MySQL common add, delete, modify and query operations (crud)
Journal des problèmes de brosse à boutons de force / day6 / 6.28
随机推荐
Neglected problem: test environment configuration management
Halcon模板匹配
模板_大整数减法_无论大小关系
Perfect JS event delegation
Scala基础教程--20--Akka
Torchdrug tutorial
基于NCF的多模块协同实例
力扣刷题日记/day3/2022.6.25
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
神经网络物联网是什么意思通俗的解释
Reptile elementary learning
[209] go language learning ideas
力扣刷题日记/day2/2022.6.24
Scala basic tutorial -- 18 -- set (2)
PB的扩展DLL开发(超级篇)(七)
中国农科院基因组所汪鸿儒课题组诚邀加入
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
被忽视的问题:测试环境配置管理
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
物联网应用技术的就业前景和现状