1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
api
auth
build
common
algorithm
app
archive
attributes
banner
bus
coder
compress
config
data
debug
file
git
http
images
json
list
logger
mapper
option
perf
queue
random
result
scheduler
secret
server
ssh
filepath.go
handler.go
key.go
reply.go
scp.go
scp_test.go
session.go
sftp.go
stringutil
svc
system
tag
template
timer
trie
version
watcher
xml
yaml
bit_flag.go
common.go
integer.go
dao
discovery
loader
mq
plugins
request
rpc
sensitive
thrift
.gitignore
LICENSE
Makefile
README.md
doc.go
error.md
go.mod
go.sum
goutils.go
goutils_test.go
version.go
克隆/下载
filepath.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2年前 . scp
package ssh
import (
"gitee.com/h79/goutils/common/file"
"io"
"os"
"path"
)
type Path struct {
Mode os.FileMode
Name string
IsDir bool
}
type FileInfo struct {
Name string
Size int64
Mode os.FileMode
}
func (fi *FileInfo) Receive(opt *Option, src io.Reader) error {
dst, err := fi.CreateFile(opt)
if err != nil {
return err
}
defer dst.Close()
n, err := file.CopyN(dst, src, fi.Size)
if err != nil {
return err
}
if n != fi.Size {
return ErrCopy
}
return nil
}
func (fi *FileInfo) CreateFile(opt *Option) (io.WriteCloser, error) {
// Create a local file to write to
dst, err := os.OpenFile(localFile(opt), os.O_RDWR|os.O_CREATE, opt.Local.Mode|fi.Mode)
if err != nil {
return nil, err
}
return dst, nil
}
func remoteFile(opt *Option) string {
if opt.Remote.IsDir {
filename := path.Base(opt.Local.Name)
opt.Remote.Name = path.Join(opt.Remote.Name, filename)
opt.Remote.IsDir = false
return filename
}
return path.Base(opt.Remote.Name)
}
func localFile(opt *Option) string {
if opt.Local.IsDir {
filename := path.Base(opt.Remote.Name)
opt.Local.Name = path.Join(opt.Local.Name, filename)
opt.Local.IsDir = false
}
return opt.Local.Name
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.8.89

搜索帮助