Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting SFTP/FTP username via Options or env var #242

Open
funkyshu opened this issue Mar 18, 2025 · 0 comments
Open

Allow setting SFTP/FTP username via Options or env var #242

funkyshu opened this issue Mar 18, 2025 · 0 comments

Comments

@funkyshu
Copy link
Member

funkyshu commented Mar 18, 2025

Currently an SFTP and FTP pass the username as part of the URI Authority section:

fs := sftp.NewFileSysetm(
    sftp.WithOptions(
        &sftp.Options{
            Password: "my-secret",
        },
    ),
)
file, _ := fs.NewFile("[email protected]:22", "/some/path/file.txt")

// or 

_ := os.SetEnv("VFS_SFTP_PASSWORD", "my-secret")
file, _ := vfssimple.NewFile("sftp://[email protected]:22/some/path/file.txt")

However, there may be cases where you'd prefer to keep that auth separate. If we add Username as an Option field (set-able via env vars as well), a user-less authority should should work just as well:

fs := sftp.NewFileSysetm(
    sftp.WithOptions(
        &sftp.Options{
            Username: "bob",
            Password: "my-secret",
        },
    ),
)
file, _ := fs.NewFile("host.com:22", "/some/path/file.txt")

// or 

_ := os.SetEnv("VFS_SFTP_USERNAME", "bob")
_ := os.SetEnv("VFS_SFTP_PASSWORD", "my-secret")
file, _ := vfssimple.NewFile("sftp://host.com:22/some/path/file.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant