del: 移除scp工具包
This commit is contained in:
@@ -1,55 +0,0 @@
|
|||||||
package ssh
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"be.ems/src/framework/config"
|
|
||||||
"be.ems/src/framework/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 网元NE 文件复制到远程文件
|
|
||||||
func FileSCPLocalToNe(neIp, localPath, nePath string) error {
|
|
||||||
usernameNe := config.Get("ne.user").(string)
|
|
||||||
// scp /path/to/local/file.txt user@remote-server:/path/to/remote/directory/
|
|
||||||
neDir := fmt.Sprintf("%s@%s:%s", usernameNe, neIp, nePath)
|
|
||||||
cmd := exec.Command("scp", "-r", localPath, neDir)
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
logger.Errorf("FileSCPLocalToNe %s => %s", output, err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 网元NE 远程文件复制到本地文件
|
|
||||||
func FileSCPNeToLocal(neIp, nePath, localPath string) error {
|
|
||||||
// 确保文件夹路径存在
|
|
||||||
if err := os.MkdirAll(filepath.Dir(localPath), 0775); err != nil {
|
|
||||||
logger.Errorf("FileSCPNeToLocal MkdirAll err %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// 如果目标文件已经存在,先将目标文件重命名
|
|
||||||
if info, err := os.Stat(localPath); err == nil && !info.IsDir() {
|
|
||||||
ext := filepath.Ext(localPath)
|
|
||||||
name := localPath[0 : len(localPath)-len(ext)]
|
|
||||||
newName := fmt.Sprintf("%s-%s%s", name, time.Now().Format("20060102_150405"), ext)
|
|
||||||
err := os.Rename(localPath, newName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
usernameNe := config.Get("ne.user").(string)
|
|
||||||
// scp user@remote-server:/path/to/remote/directory/ /path/to/local/file.txt
|
|
||||||
neDir := fmt.Sprintf("%s@%s:%s", usernameNe, neIp, nePath)
|
|
||||||
cmd := exec.Command("scp", "-r", neDir, localPath)
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
logger.Errorf("FileSCPNeToLocal %s => %s", output, err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user