当前位置:网站首页>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
}
边栏推荐
- Caché WebSocket
- [opencv introduction to mastery 9] opencv video capture, image and video conversion
- Scala基础教程--14--隐式转换
- How is the entered query SQL statement executed?
- Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)
- 基于NCF的多模块协同实例
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- 力扣刷题日记/day7/2022.6.29
- Scala基础教程--20--Akka
- Deleting nodes in binary search tree
猜你喜欢
同事悄悄告诉我,飞书通知还能这样玩
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
Principle and application of ThreadLocal
Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)
力扣刷題日記/day6/6.28
TCP waves twice, have you seen it? What about four handshakes?
Scala basic tutorial -- 15 -- recursion
【uniapp】uniapp开发app在线预览pdf文件
Li Kou brush question diary /day4/6.26
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
随机推荐
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
[209] go language learning ideas
Lua emmylua annotation details
Li Kou brush question diary /day2/2022.6.24
正则替换【JS,正则表达式】
Li Kou brush question diary /day4/6.26
[go ~ 0 to 1] read, write and create files on the sixth day
ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
资料下载 丨首届腾讯技术开放日课程精华!
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
2022年字节跳动日常实习面经(抖音)
Scala基础教程--12--读写数据
[mathematical basis of machine learning] (I) linear algebra (Part 1 +)
6.26cf simulation race e: solution to the problem of price maximization
Pb extended DLL development (super chapter) (VII)
Scala基础教程--20--Akka
线上MySQL的自增id用尽怎么办?
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
基于lex和yacc的词法分析器+语法分析器
C language printing exercise