-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Son Roy Almerol
committed
Nov 11, 2024
1 parent
c708a3a
commit 45abc06
Showing
7 changed files
with
164 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//go:build windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/sonroyaalmerol/pbs-plus/internal/agent/sftp" | ||
"github.com/sonroyaalmerol/pbs-plus/internal/utils" | ||
) | ||
|
||
type Drive struct { | ||
Letter string | ||
ErrorChan chan string | ||
} | ||
|
||
func getLocalDrives() (r []Drive) { | ||
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" { | ||
f, err := os.Open(string(drive) + ":\\") | ||
if err == nil { | ||
r = append(r, Drive{Letter: string(drive)}) | ||
f.Close() | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (drive *Drive) serveSFTP(p *agentService) error { | ||
rune := []rune(drive.Letter)[0] | ||
sftpConfig, err := sftp.InitializeSFTPConfig(p.svc, drive.Letter) | ||
if err != nil { | ||
return fmt.Errorf("Unable to initialize SFTP config: %s", err) | ||
} | ||
if err := sftpConfig.PopulateKeys(); err != nil { | ||
return fmt.Errorf("Unable to populate SFTP keys: %s", err) | ||
} | ||
|
||
port, err := utils.DriveLetterPort(rune) | ||
if err != nil { | ||
return fmt.Errorf("Unable to map letter to port: %s", err) | ||
} | ||
|
||
go sftp.Serve(p.ctx, drive.ErrorChan, sftpConfig, "0.0.0.0", port, drive.Letter) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.