fix 远程网元scp复制文件
This commit is contained in:
@@ -561,23 +561,23 @@ func (s *UdmUserApi) UdmAuthUserImport(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 文件名
|
||||
fileName := fmt.Sprintf("OMC_AUTH_USER_IMPORT_%s_%d_%s", neId, time.Now().UnixMilli(), fileHeader.Filename)
|
||||
filePath := fmt.Sprintf("%s/upload/mml/%s", conf.Get("ne.omcdir"), fileName)
|
||||
dstPath := conf.Get("mml.upload").(string)
|
||||
localPath := fmt.Sprintf("%s/upload/mml/%s", conf.Get("ne.omcdir"), fileName)
|
||||
nePath := conf.Get("mml.upload").(string)
|
||||
// 输出保存文件
|
||||
err = ctx.SaveUploadedFile(r, filePath)
|
||||
err = ctx.SaveUploadedFile(r, localPath)
|
||||
if err != nil {
|
||||
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 复制到远程
|
||||
err = file.FileNeSCP(neInfo.Ip, filePath, dstPath)
|
||||
err = file.FileSCPLocalToNe(neInfo.Ip, localPath, nePath)
|
||||
if err != nil {
|
||||
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("import authdat:path=%s", fmt.Sprintf("%s/%s", dstPath, fileName))
|
||||
msg := fmt.Sprintf("import authdat:path=%s", fmt.Sprintf("%s/%s", nePath, fileName))
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.Ip, msg)
|
||||
@@ -589,12 +589,12 @@ func (s *UdmUserApi) UdmAuthUserImport(w http.ResponseWriter, r *http.Request) {
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.HasSuffix(fileHeader.Filename, ".csv") {
|
||||
data := file.ReadCSVFile(filePath)
|
||||
data := file.ReadCSVFile(localPath)
|
||||
neId = "-"
|
||||
s.authUser.InsertCSV(neId, data)
|
||||
}
|
||||
if strings.HasSuffix(fileHeader.Filename, ".txt") {
|
||||
data := file.ReadTxtFile(filePath)
|
||||
data := file.ReadTxtFile(localPath)
|
||||
neId = "-"
|
||||
s.authUser.InsertTxt(neId, data)
|
||||
}
|
||||
@@ -1125,23 +1125,23 @@ func (s *UdmUserApi) UdmSubUserImport(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 文件名
|
||||
fileName := fmt.Sprintf("OMC_SUB_USER_IMPORT_%s_%d_%s", neId, time.Now().UnixMilli(), fileHeader.Filename)
|
||||
filePath := fmt.Sprintf("%s/upload/mml/%s", conf.Get("ne.omcdir"), fileName)
|
||||
dstPath := conf.Get("mml.upload").(string)
|
||||
localPath := fmt.Sprintf("%s/upload/mml/%s", conf.Get("ne.omcdir"), fileName)
|
||||
nePath := conf.Get("mml.upload").(string)
|
||||
// 输出保存文件
|
||||
err = ctx.SaveUploadedFile(r, filePath)
|
||||
err = ctx.SaveUploadedFile(r, localPath)
|
||||
if err != nil {
|
||||
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 复制到远程
|
||||
err = file.FileNeSCP(neInfo.Ip, filePath, dstPath)
|
||||
err = file.FileSCPLocalToNe(neInfo.Ip, localPath, nePath)
|
||||
if err != nil {
|
||||
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("import udmuser:path=%s", fmt.Sprintf("%s/%s", dstPath, fileName))
|
||||
msg := fmt.Sprintf("import udmuser:path=%s", fmt.Sprintf("%s/%s", nePath, fileName))
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.Ip, msg)
|
||||
@@ -1152,12 +1152,12 @@ func (s *UdmUserApi) UdmSubUserImport(w http.ResponseWriter, r *http.Request) {
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.HasSuffix(fileHeader.Filename, ".csv") {
|
||||
data := file.ReadCSVFile(filePath)
|
||||
data := file.ReadCSVFile(localPath)
|
||||
neId = "-"
|
||||
s.subUser.InsertCSV(neId, data)
|
||||
}
|
||||
if strings.HasSuffix(fileHeader.Filename, ".txt") {
|
||||
data := file.ReadTxtFile(filePath)
|
||||
data := file.ReadTxtFile(localPath)
|
||||
neId = "-"
|
||||
s.subUser.InsertTxt(neId, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user