Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| func runSFTPBatch(alias string, commands []string, postProcess func(string) error) error { | ||
| session, err := loadSession(alias) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if session.Protocol != config.ProtocolSFTP { | ||
| return fmt.Errorf("session '%s' is not configured for SFTP", session.Alias) | ||
| } | ||
|
|
||
| password, err := promptPassword(session) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| batch := strings.Join(commands, "\n") + "\n" | ||
| args := buildSFTPArgs(session) | ||
| cmd := exec.Command("sftp", args...) | ||
| cmd.Stdin = strings.NewReader(batch) | ||
| var stdout, stderr bytes.Buffer | ||
| cmd.Stdout = &stdout | ||
| cmd.Stderr = &stderr | ||
|
|
||
| if password != "" { | ||
| fmt.Println(utils.Yellow, "Note: Enter the password when prompted by sftp.", utils.Reset) | ||
| } | ||
|
|
||
| if err := cmd.Run(); err != nil { | ||
| output := stderr.String() | ||
| if output == "" { | ||
| output = stdout.String() | ||
| } | ||
| return fmt.Errorf("sftp command failed: %s", strings.TrimSpace(output)) |
There was a problem hiding this comment.
Batch SFTP has no way to provide passwords
The new SFTP commands always run sftp in batch mode with cmd.Stdin set to the command script and both Stdout/Stderr captured into buffers. For sessions that use password authentication, promptPassword asks the user for a password but the value is never forwarded to the spawned sftp process, nor is the process attached to the terminal so it can prompt on its own. As a result, any password-protected SFTP session will fail (or hang) because sftp cannot read the password. Only key-based sessions work. When RequiresPass is true, STDIN/STDOUT should remain attached to the terminal and the collected password should be supplied (e.g. via sshpass or by letting sftp prompt directly).
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68f757587ce8832cb8ce5a4a55e348c0