StarSSH release

master
兔子 5 years ago
parent 2a62e53e7f
commit 2c1ec13a0c

@ -9,8 +9,6 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"os" "os"
"path"
"path/filepath"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@ -469,14 +467,14 @@ func CreateSftp(client *ssh.Client) (*sftp.Client, error) {
return sftpClient, err return sftpClient, err
} }
func FtpTransferOut(localFilePath, remoteDir string, sftpClient *sftp.Client) error { func FtpTransferOut(localFilePath, remotePath string, sftpClient *sftp.Client) error {
srcFile, err := os.Open(localFilePath) srcFile, err := os.Open(localFilePath)
if err != nil { if err != nil {
return err return err
} }
defer srcFile.Close() defer srcFile.Close()
var remoteFileName = filepath.Base(localFilePath) // var remoteFileName = filepath.Base(localFilePath)
dstFile, err := sftpClient.Create(path.Join(remoteDir, remoteFileName)) dstFile, err := sftpClient.Create(remotePath)
if err != nil { if err != nil {
return err return err
} }
@ -492,28 +490,33 @@ func FtpTransferOut(localFilePath, remoteDir string, sftpClient *sftp.Client) er
return nil return nil
} }
func FtpTransferOutFunc(localFilePath, remoteDir string, bufcap int, rtefunc func(int), sftpClient *sftp.Client) error { func FtpTransferOutFunc(localFilePath, remotePath string, bufcap int, rtefunc func(float64), sftpClient *sftp.Client) error {
num := 0 num := 0
srcFile, err := os.Open(localFilePath) srcFile, err := os.Open(localFilePath)
if err != nil { if err != nil {
return err return err
} }
defer srcFile.Close() defer srcFile.Close()
var remoteFileName = filepath.Base(localFilePath) stat, _ := os.Stat(localFilePath)
dstFile, err := sftpClient.Create(path.Join(remoteDir, remoteFileName)) filebig := float64(stat.Size())
//var remoteFileName = filepath.Base(localFilePath)
dstFile, err := sftpClient.Create(remotePath)
if err != nil { if err != nil {
return err return err
} }
defer dstFile.Close() defer dstFile.Close()
for { for {
buf := make([]byte, 1024) buf := make([]byte, bufcap)
n, err := srcFile.Read(buf) n, err := srcFile.Read(buf)
dstFile.Write(buf[:n])
num++
rtefunc(num)
if err == io.EOF { if err == io.EOF {
break break
} }
if err != nil {
return err
}
num += n
go rtefunc(float64(num) / filebig * 100)
dstFile.Write(buf[:n])
} }
return nil return nil
} }
@ -524,8 +527,8 @@ func FtpTransferIn(src, dst string, sftpClient *sftp.Client) error {
return err return err
} }
defer srcFile.Close() defer srcFile.Close()
var localFileName = filepath.Base(src) //var localFileName = filepath.Base(src)
dstFile, err := os.Create(filepath.Join(dst, localFileName)) dstFile, err := os.Create(dst)
if err != nil { if err != nil {
return err return err
} }
@ -538,28 +541,33 @@ func FtpTransferIn(src, dst string, sftpClient *sftp.Client) error {
return nil return nil
} }
func FtpTransferInFunc(src, dst string, bufcap int, rtefunc func(int), sftpClient *sftp.Client) error { func FtpTransferInFunc(src, dst string, bufcap int, rtefunc func(float64), sftpClient *sftp.Client) error {
num := 0 num := 0
srcFile, err := sftpClient.Open(src) srcFile, err := sftpClient.Open(src)
if err != nil { if err != nil {
return err return err
} }
defer srcFile.Close() defer srcFile.Close()
var localFileName = filepath.Base(src) stat, _ := srcFile.Stat()
dstFile, err := os.Create(filepath.Join(dst, localFileName)) filebig := float64(stat.Size())
//var localFileName = filepath.Base(src)
dstFile, err := os.Create(dst)
if err != nil { if err != nil {
return err return err
} }
defer dstFile.Close() defer dstFile.Close()
for { for {
buf := make([]byte, 1024) buf := make([]byte, bufcap)
n, err := srcFile.Read(buf) n, err := srcFile.Read(buf)
dstFile.Write(buf[:n])
num++
rtefunc(num)
if err == io.EOF { if err == io.EOF {
break break
} }
if err != nil {
return err
}
num += n
go rtefunc(float64(num) / filebig * 100)
dstFile.Write(buf[:n])
} }
return nil return nil
} }

Loading…
Cancel
Save