-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (37 loc) · 1.04 KB
/
main.go
File metadata and controls
44 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"os"
"golang.org/x/crypto/ssh"
)
// Test connectivity to SFTP server.
// Usage: sftptest <host>:<port> <user> <password>
// Example: sftptest ftp.example.com:22 root password
// Note: Make sure port number is specified.
func main() {
// Retrieve host, username and password from command line arguments.
args := os.Args
if len(args) < 4 {
fmt.Fprintf(os.Stderr, "Usage: sftptest <host>:<port> <user> <password>\nExample: sftptest ftp.example.com:22 root password")
os.Exit(1)
}
host := args[1]
username := args[2]
password := args[3]
config := &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{
ssh.Password(password),
},
// `InsecureIgnoreHostKey` is not recommended. Consider other more secured method for verifying host key
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
// Establishing connection
conn, err := ssh.Dial("tcp", host, config)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to dial: %v\n", err)
os.Exit(1)
}
defer conn.Close()
fmt.Println("Connection successful")
}