MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / RemoteUpload

Method RemoteUpload

cli/pkg/common/sshremote.go:924–1007  ·  view source on GitHub ↗
(filesMaps map[string]string)

Source from the content-addressed store, hash-verified

922}
923
924func (instance *SSHRemote) RemoteUpload(filesMaps map[string]string) (err error) {
925 // initialize SSH connection
926 var clientConfig *ssh.ClientConfig
927
928 if len(instance.SSHPassword) > 0 {
929
930 if len(strings.TrimSpace(instance.SSHPassword)) == 0 {
931 SmartIDELog.Error(i18nInstance.Common.Err_ssh_password_required)
932 }
933
934 clientConfig = &ssh.ClientConfig{
935 User: instance.SSHUserName,
936 Auth: []ssh.AuthMethod{
937 ssh.Password(instance.SSHPassword),
938 },
939 Timeout: 30 * time.Second, // 30 秒超时
940 // 解决 “ssh: must specify HostKeyCallback” 的问题
941 HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
942 return nil
943 },
944 }
945
946 } else { // 如果用户不输入用户名和密码,则尝试使用ssh key pair的方式链接远程服务器
947 //var hostKey ssh.PublicKey
948 homePath, err := os.UserHomeDir()
949 if err != nil {
950 CheckError(err)
951 }
952 filePath := filepath.Join(homePath, "/.ssh/id_rsa")
953 if SmartIDELog.Ws_id != "" && ServerUserName != "" {
954 filePath = fmt.Sprintf("%s_%s_%s", filePath, ServerUserName, SmartIDELog.Ws_id)
955 }
956 key, err := os.ReadFile(filePath)
957 CheckError(err, "unable to read private key:")
958
959 // Create the Signer for this private key.
960 signer, err := ssh.ParsePrivateKey(key)
961 CheckError(err, "unable to parse private key:")
962
963 clientConfig = &ssh.ClientConfig{
964 User: instance.SSHUserName,
965 Auth: []ssh.AuthMethod{
966 // Use the PublicKeys method for remote authentication.
967 ssh.PublicKeys(signer),
968 },
969 HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
970 // use OpenSSH's known_hosts file if you care about host validation
971 return nil
972 },
973 }
974
975 }
976
977 addr := fmt.Sprintf("%v:%v", instance.SSHHost, instance.SSHPort)
978
979 if err == nil {
980 for k, v := range filesMaps {
981

Callers

nothing calls this directly

Calls 4

CheckErrorFunction · 0.85
CopyFileMethod · 0.80
ErrorMethod · 0.45
JoinMethod · 0.45

Tested by

no test coverage detected