Manage SFTP AutoDisconnect and idle timeouts
mainBecause vfs.FileSystem lacks an explicit Close() method, the SFTP backend implements an automatic disconnection mechanism to release resources.
How it works
- After a connection is established, a timer starts.
- The connection is closed if it remains idle for the duration specified in
Options.AutoDisconnect(default is 10 seconds). - Any server-side request (e.g.,
List,Read,Touch) resets this timer. - If the timer expires, the connection closes. The next request will trigger a fresh reconnection.
Configuration
Set Options.AutoDisconnect (integer seconds) to adjust the idle timeout.
// Example of idle behavior
fs := sftp.NewFileSystem()
loc, _ := fs.NewLocation("user@server:22", "/path/")
file, _ := loc.NewFile("file.txt")
file.Touch() // Starts 10s timer
_, _ = loc.List() // Resets timer
time.Sleep(15 * time.Second) // Timer expires, connection closes
_, _ = loc.List() // Reconnects automatically