当前位置:网站首页>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
}
边栏推荐
- NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
- Detailed explanation of the maturity classification of ITSS operation and maintenance capability | one article clarifies the ITSS certificate
- 力扣刷题日记/day5/2022.6.27
- 基于unity的愤怒的小鸟设计
- Neglected problem: test environment configuration management
- uni-app与uviewUI实现仿小米商城app(附源码)
- C语言打印练习
- C language printing exercise
- How to modify icons in VBS or VBE
- 资料下载 丨首届腾讯技术开放日课程精华!
猜你喜欢
随机推荐
力扣刷题日记/day4/6.26
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Li Kou brush question diary /day1/2022.6.23
C language printing exercise
PB的扩展DLL开发(超级篇)(七)
Is it safe to open an account online? is that true?
一、C语言入门基础
1、 Introduction to C language
力扣刷题日记/day6/6.28
同事悄悄告诉我,飞书通知还能这样玩
Scala basic tutorial -- 17 -- Collection
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
Mxnet implementation of googlenet (parallel connection network)
File processing examples of fopen, FREAD, fwrite, fseek
Scala基础教程--17--集合
Journal des problèmes de brosse à boutons de force / day6 / 6.28
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
[211] go handles the detailed documents of Excel library
基于C语言的菜鸟驿站管理系统
力扣刷题日记/day8/7.1