fix: correct issue with file copygin

This commit is contained in:
Jose Diaz-Gonzalez committed 2024-01-23 03:00:27 -05:00
1 parent 707c22eae7
commit 09ca1f1299
1 file changed
+5 -15
+5 -15
View File
@@ -18,20 +18,17 @@ import (
// SftpCopyInput is the input for CallSftpCopy // SftpCopyInput is the input for CallSftpCopy
type SftpCopyInput struct { type SftpCopyInput struct {
// SourcePath is the path to the file to copy // AllowUknownHosts allows connecting to hosts with unknown host keys
SourcePath string AllowUknownHosts bool
// DestinationPath is the path to copy the file to // DestinationPath is the path to copy the file to
DestinationPath string DestinationPath string
// AllowUknownHosts allows connecting to hosts with unknown host keys
AllowUknownHosts bool
// RemoteHost is the remote host to connect to // RemoteHost is the remote host to connect to
RemoteHost string RemoteHost string
// Sudo runs the command with sudo -n -u root // SourcePath is the path to the file to copy
Sudo bool SourcePath string
} }
// CallSftpCopy copies a file to a remote host via sftp // CallSftpCopy copies a file to a remote host via sftp
@@ -226,14 +223,7 @@ func (task SftpCopyTask) Execute(ctx context.Context) (SftpCopyResult, error) {
return SftpCopyResult{}, fmt.Errorf("failed to create sftp client: %w", err) return SftpCopyResult{}, fmt.Errorf("failed to create sftp client: %w", err)
} }
srcFile, err := os.Open(task.SourcePath) contents, err := os.ReadFile(task.SourcePath)
if err != nil {
return SftpCopyResult{}, fmt.Errorf("failed to open source file: %w", err)
}
defer srcFile.Close()
var contents []byte
_, err = srcFile.Read(contents)
if err != nil { if err != nil {
return SftpCopyResult{}, fmt.Errorf("failed to read source file: %w", err) return SftpCopyResult{}, fmt.Errorf("failed to read source file: %w", err)
} }