MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / DownloadFile

Function DownloadFile

utils/ssh.go:633–667  ·  view source on GitHub ↗
(client *SSHClient, remotePath, localPath string)

Source from the content-addressed store, hash-verified

631}
632
633func DownloadFile(client *SSHClient, remotePath, localPath string) error {
634 if client == nil || client.client == nil {
635 return fmt.Errorf("SSH client is not connected")
636 }
637
638 session, err := client.client.NewSession()
639 if err != nil {
640 return fmt.Errorf("failed to create session: %w", err)
641 }
642 defer session.Close()
643
644 stdout, err := session.StdoutPipe()
645 if err != nil {
646 return fmt.Errorf("failed to get stdout pipe: %w", err)
647 }
648
649 if err := session.Start(fmt.Sprintf("cat %s", remotePath)); err != nil {
650 return fmt.Errorf("failed to start cat command: %w", err)
651 }
652
653 data, err := io.ReadAll(stdout)
654 if err != nil {
655 return fmt.Errorf("failed to read data: %w", err)
656 }
657
658 if err := session.Wait(); err != nil {
659 return fmt.Errorf("failed to download file: %w", err)
660 }
661
662 if err := os.WriteFile(localPath, data, 0644); err != nil {
663 return fmt.Errorf("failed to write local file: %w", err)
664 }
665
666 return nil
667}
668
669func IsAuthError(err error) bool {
670 if err == nil {

Callers

nothing calls this directly

Calls 2

CloseMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected