-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 1018 Bytes
/
main.go
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
package main
import (
"fmt"
"os"
sftp "github.com/mmaous/sftp-uploader/utils"
)
func main() {
localFolderPath := os.Getenv("LOCAL_FOLDER_PATH")
remoteFolderPath := os.Getenv("REMOTE_FOLDER_PATH")
username := os.Getenv("VM_USERNAME")
password := os.Getenv("VM_PASSWORD")
host := os.Getenv("HOST")
port := os.Getenv("PORT")
if port == "" {
port = "22"
}
client, err := sftp.SetupSSHClient(host, port, username, password)
if err != nil {
fmt.Printf("Failed to set up SSH client: %v\n", err)
return
}
defer client.Close()
err = sftp.ChangeDirectory(client, remoteFolderPath)
if err != nil {
fmt.Printf("Failed to change directory to %s on the remote server: %v\n", remoteFolderPath, err)
return
}
transferredFilesCount, err := sftp.TransferFiles(client, localFolderPath, remoteFolderPath)
if err != nil {
fmt.Printf("Failed to transfer files: %v\n", err)
return
}
fmt.Printf("Transferred %d files.\n", transferredFilesCount)
fmt.Println("All files uploaded successfully.")
}