59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/SommerEngineering/Sync/Sync"
|
|
"golang.org/x/crypto/ssh"
|
|
"log"
|
|
"runtime"
|
|
)
|
|
|
|
func main() {
|
|
|
|
// Show the current version:
|
|
fmt.Println(`Sync v1.0.0`)
|
|
|
|
// Allow Go to use all CPUs:
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
// Read the configuration from the command-line args:
|
|
readFlags()
|
|
|
|
// Check if the directories are provided:
|
|
if localDir == `` || remoteDir == `` {
|
|
log.Println(`Please provide the local and remote directory.`)
|
|
return
|
|
}
|
|
|
|
// Check if the password was provided:
|
|
for true {
|
|
if password == `` {
|
|
// Promt for the password:
|
|
fmt.Println(`Please provide the password for the connection:`)
|
|
fmt.Scanln(&password)
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
|
|
// Create the SSH configuration:
|
|
Sync.SetPassword4Callback(password)
|
|
config := &ssh.ClientConfig{
|
|
User: username,
|
|
Auth: []ssh.AuthMethod{
|
|
ssh.Password(password),
|
|
ssh.PasswordCallback(Sync.PasswordCallback),
|
|
ssh.KeyboardInteractive(Sync.KeyboardInteractiveChallenge),
|
|
},
|
|
}
|
|
|
|
// Connect to the SSH server:
|
|
ssh := Sync.ConnectSSH(config, serverAddrString)
|
|
if ssh == nil {
|
|
log.Println(`It was not possible to connect to the SSH server.`)
|
|
return
|
|
}
|
|
|
|
defer ssh.Close()
|
|
}
|