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

本文介绍如何使用Node.js编写代码,创建解压批处理,然后通过FTP和SSH将打包后的代码上传到服务器。重点在于上传流程和使用的工具,如`uploadCode`接口、build.bat、upload.bat和upload.ftp脚本。
摘要由CSDN通过智能技术生成

 

 

 

接口:

//上传代码到目标服务器
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐同保

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值