modulepackage
2.1.0+incompatible
Repository: https://github.com/saitho/golang-extended-fs.git
Documentation: pkg.go.dev
# README
Extended FS
This library allows accessing local and remote files and performing file operations, using the same API.
- Read a file from local file system:
stringContent, err := ReadFile("/var/www/html/index.html")
- Read a file from the configured remote file system:
stringContent, err := ReadFile("sftp:///var/www/html/index.html")
Target
- Local: just set an absolute or relative file path, e.g.
/var/www/html
- Remote: just add
ssh://
orsftp://
protocol before the location, e.g.ssh:///var/www/html
orsftp:///var/www/html
Examples
Write local file
This will create a file /var/www/html/index.html
with a HTML content on the local file system.
import "github.com/saitho/golang-extended-fs/v2"
extended_fs.WriteFile("/var/www/html/index.html", "<h1>Hello World</h1>")
Write remote file
This will create a remote file /var/www/html/index.html
with a HTML content on the remote file system at 192.168.2.105
.
Local SSH keys are always loaded per default. Additionally, a custom key can be specified via SshIdentify
setting.2
See SFTP config for all available settings.
import (
"github.com/saitho/golang-extended-fs/v2"
"github.com/saitho/golang-extended-fs/v2/sftp"
)
sftp.Config.SshHost = "192.168.2.105"
extended_fs.WriteFile("ssh:///var/www/html/index.html", "<h1>Hello World</h1>")
import (
"github.com/saitho/golang-extended-fs/v2"
"github.com/saitho/golang-extended-fs/v2/sftp"
)
sftp.Config.SshHost = "192.168.2.105"
sftp.Config.LoadLocalSigners = false // do not load local SSH private keys
sftp.Config.SshIdentity = "/path/to/my/private_key.pem"
extended_fs.WriteFile("ssh:///var/www/html/index.html", "<h1>Hello World</h1>")
extended_fs.Chown("ssh:///var/www/html/index.html", 1001, 1001) // set user and group with id 1001 as owner
# Functions
AppendToFile will append file content to an existing one.
Chmod will change the permissions of a file or directory.
Chown will change the owner of a file or directory.
CopyFile will read all contents of a given file and write it to another location.
CreateFolder will create a new folder.
DeleteFile will delete the given file.
DeleteFolder will delete an existing folder.
HasFile will return true if file exists.
HasFolder will return true if a folder exists.
ListFolders will list all folders within a given folder.
ReadFile will read all contents of a given file.
WriteFile will write a file content to a new file or override an existing one.
# Variables
No description provided by the author