自动化,压缩前端工程代码使用ftp上传到服务器,ssh登录服务器,解压上传的压缩代码

 

 

 

接口:

//上传代码到目标服务器
const uploadCode = (req, res) => {
  const { buildPath, targetPath } = req.body
  const buildBat = 
`
echo unzip start
cd /temp/zip
7z x /temp/zip/build.tar -o/temp/unzip -y
xcopy \\temp\\unzip\\build ${targetPath} /Y /E
echo success
`

  //创建用于解压的批处理文件
  fs.writeFileSync('/temp/zip/build.bat', buildBat, { encoding: 'utf8' }, (err) => {})
  //上传build压缩包到服务器
  spawn.sync(`./light/jenkins/upload.bat ${buildPath} ${targetPath}`, [], {
    stdio: 'inherit'
  })

  res.send({
    state: 1,
    data: {
      buildPath,
      targetPath
    },
    message: '成功'
  })
}

upload.bat:

echo %0 %1 %2
7z.exe a \temp\zip\build.tar %1
ftp -s:C:\ftp\upload.ftp
ssh Administrator@39.97.238.175 "cd \temp\zip && ls && call .\build.bat"

upload.ftp:

open www.xutongbao.top
root
您的密码
cd temp\zip
put \temp\zip\build.tar
put \temp\zip\build.bat
ls
bye

posted @ 2021-11-12 13:51  徐同保  阅读(3)  评论(0编辑  收藏  举报  来源