使用 nant 通过 FTP 上传文件

发布于 2024-08-31 22:08:24 字数 159 浏览 5 评论 0 原文

我有一个用于构建 .NET 项目的 NAnt 脚本,我想看看是否有办法使用 FTP 任务将生成的程序集上传到某个远程文件夹。

我在网上找不到任何好的例子,我想知道是否有人知道如何做到这一点,是否可行。

仅供参考:我正在 Windows 机器上运行它,如果有什么区别的话。

I have an NAnt script that I use to build my .NET project, and I'm looking to see if there is a way to upload the resulted assemblies to some remote folder using an FTP task.

I couldn't find any good example online, and I'm wondering if anyone knows how to do it, if it's doable at all.

FYI: I'm running it on a windows machine, if it makes any difference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

生寂 2024-09-07 22:08:24

您可以使用 WinSCP 作为 任务。使用 WinSCP 将使您能够获得额外的好处,例如同步

这就是我们正在做的事情,而且它的作用就像一种魅力。

You could use WinSCP as console application in a NAnt <exec> task. Using WinSCP will give You access to extra goodies like synchronization.

That's what we are doing and it works like a charm.

攒一口袋星星 2024-09-07 22:08:24

此处的工作 WinSCP 示例:

    <exec
        verbose="true"
        program="WinSCP.exe" 
        basedir="${WinSCP.Folder.Install}">
        <arg value="/command" />
        <arg value="/log=D:\Logs\WinSCP\winscp.log" />
        <arg value="/script=backup.winscp" />
        <arg line="/parameter ${YOUR_FILE}" />
    </exec>

上面的 exec 中的 backup.winscp 是一个具有以下内容的文件

option batch abort
option confirm off 
open ftp://user:[email protected]
put "%1%"
exit

Working WinSCP example here:

    <exec
        verbose="true"
        program="WinSCP.exe" 
        basedir="${WinSCP.Folder.Install}">
        <arg value="/command" />
        <arg value="/log=D:\Logs\WinSCP\winscp.log" />
        <arg value="/script=backup.winscp" />
        <arg line="/parameter ${YOUR_FILE}" />
    </exec>

where backup.winscp in above exec is a file with the following content

option batch abort
option confirm off 
open ftp://user:[email protected]
put "%1%"
exit
顾铮苏瑾 2024-09-07 22:08:24

我自己也有同样的需求,因此开发了一个基本的 FTP 上传 NAnt 任务。您可以在这里找到它:
https://sourceforge.net/projects/w3c-nant/

示例用法(复制粘贴自站点的 API 文档):

<ftpUpload host="ftp.myserver.com" username="root" password="r00t" todir="/">
    <fileset basedir="dist">
        <include name="**/*" />
        <exclude name="**/*.config" />
    </fileset>
</ftpUpload>

我已经在本地构建脚本中使用它来将我的站点上传到其实时服务器。

Having the same need myself, I developed a basic FTP upload NAnt task. You can find it here:
https://sourceforge.net/projects/w3c-nant/

Example usage (copy pasted from the site's API docs):

<ftpUpload host="ftp.myserver.com" username="root" password="r00t" todir="/">
    <fileset basedir="dist">
        <include name="**/*" />
        <exclude name="**/*.config" />
    </fileset>
</ftpUpload>

I already use it in my local build scripts to upload my site to its live server.

待"谢繁草 2024-09-07 22:08:24

您可以使用 WinSCP(适用于 Windows 的免费 ftp 客户端)并通过 nant“exec”标签集成它。设置相当简单,一旦完成,它就会像魅力一样发挥作用。

You may use the WinSCP (free ftp client for windows) and integrate it through nant "exec" tag. The setup is fairly straight forward and once it's done it works like a charm.

眼眸里的那抹悲凉 2024-09-07 22:08:24

我们使用这样的东西(NAnt-0.86-beta1):

<!-- Copies files from artifacts folder to destination folder -->
<target name="deploy-configuration">
  <!-- Generate temporary folder for the processed web.config -->
  <property name="generated-config-file-path" value="${path::get-temp-path()}${common::GenerateGUID()}" />
  <mkdir dir="${generated-config-file-path}" />
  <!-- Copy -->
  <copy file="${artifacts.dir}/web.config" tofile="${generated-config-file-path}/web.config" />
  <!-- Update web.config with values for our destination environment before we deploy. -->
  <update-configuration-path file="${generated-config-file-path}\web.config" />
  <!-- Deploy using FTP -->
  <connection id="ftp-transfer-connection"
    server="${project.deployment.ftp.server}"
    username="${project.deployment.ftp.user}"
    password="${project.deployment.ftp.password}"
    />

  <ftp connection="ftp-transfer-connection"
       showdironconnect="false"
       createdirs="true"
       verbose="true"
       exec="true"
       logfiles="false"
       >

    <put type="bin"
         localdir="${generated-config-file-path}"
         remotedir="${project.deployment.path.remote}"
         flatten="false"
         >
      <include name="**\web.config" />
    </put>
  </ftp>
  <delete dir="${generated-config-file-path}" />
</target>


<target name="deploy">

  <connection id="ftp-transfer-connection"
    server="${project.deployment.ftp.server}"
    username="${project.deployment.ftp.user}"
    password="${project.deployment.ftp.password}"
    />

  <ftp connection="ftp-transfer-connection"
       showdironconnect="false"
       createdirs="true"
       verbose="true"
       exec="true"
       logfiles="false"
       >

    <put type="bin"
         localdir="${artifacts.dir}"
         remotedir="${project.deployment.path.remote}"
         flatten="false"
         >
      <include name="**\bin\**" />
      <include name=".\*.svc" />
      <include name=".\web.config" />
    </put>
  </ftp>
  <!-- Deploy configuration -->
  <call target="deploy-configuration" />
</target>

We using something like this (NAnt-0.86-beta1):

<!-- Copies files from artifacts folder to destination folder -->
<target name="deploy-configuration">
  <!-- Generate temporary folder for the processed web.config -->
  <property name="generated-config-file-path" value="${path::get-temp-path()}${common::GenerateGUID()}" />
  <mkdir dir="${generated-config-file-path}" />
  <!-- Copy -->
  <copy file="${artifacts.dir}/web.config" tofile="${generated-config-file-path}/web.config" />
  <!-- Update web.config with values for our destination environment before we deploy. -->
  <update-configuration-path file="${generated-config-file-path}\web.config" />
  <!-- Deploy using FTP -->
  <connection id="ftp-transfer-connection"
    server="${project.deployment.ftp.server}"
    username="${project.deployment.ftp.user}"
    password="${project.deployment.ftp.password}"
    />

  <ftp connection="ftp-transfer-connection"
       showdironconnect="false"
       createdirs="true"
       verbose="true"
       exec="true"
       logfiles="false"
       >

    <put type="bin"
         localdir="${generated-config-file-path}"
         remotedir="${project.deployment.path.remote}"
         flatten="false"
         >
      <include name="**\web.config" />
    </put>
  </ftp>
  <delete dir="${generated-config-file-path}" />
</target>


<target name="deploy">

  <connection id="ftp-transfer-connection"
    server="${project.deployment.ftp.server}"
    username="${project.deployment.ftp.user}"
    password="${project.deployment.ftp.password}"
    />

  <ftp connection="ftp-transfer-connection"
       showdironconnect="false"
       createdirs="true"
       verbose="true"
       exec="true"
       logfiles="false"
       >

    <put type="bin"
         localdir="${artifacts.dir}"
         remotedir="${project.deployment.path.remote}"
         flatten="false"
         >
      <include name="**\bin\**" />
      <include name=".\*.svc" />
      <include name=".\web.config" />
    </put>
  </ftp>
  <!-- Deploy configuration -->
  <call target="deploy-configuration" />
</target>
不必在意 2024-09-07 22:08:24

我想与您分享我的任务。我只使用 arg 值。工作正常。这是我的脚本:

<property name="path.to.root" value="${project::get-base-directory()}\"/>
<property name = "deploy.folder" value = "${path.to.root}Deploy" />

<!-- FTP -->
<property name = "ftp.host" value = "127.0.0.1"/>
<property name = "ftp.port" value="21"/>
<property name = "ftp.user" value = "username"/>
<property name = "ftp.password" value="mypass"/>        
<property name = "ftp.local.dir" value = "${deploy.folder}" />

<!-- WinSCP-->
<property name = "winscp.run" value ="${path.to.root}\tools\WinSCP\WinSCP.com"/>

<target description="Copy to the FTP server" name="ftp.copy">
    <exec program="${winscp.run}">
        <arg value="/command" />
        <arg value="option batch abort" />
        <arg value="option confirm off" />
        <arg value="option transfer binary" />
        <arg value="open ftp://${ftp.user}:${ftp.password}@${ftp.host}:${ftp.port}" />
        <arg value= '"put ""${ftp.local.dir}"""' />         
        <arg value="close" />
        <arg value="exit" />
    </exec>     
</target>

玩得开心!

I would like to share with you my task. I just use arg values. It works ok. Here's my script:

<property name="path.to.root" value="${project::get-base-directory()}\"/>
<property name = "deploy.folder" value = "${path.to.root}Deploy" />

<!-- FTP -->
<property name = "ftp.host" value = "127.0.0.1"/>
<property name = "ftp.port" value="21"/>
<property name = "ftp.user" value = "username"/>
<property name = "ftp.password" value="mypass"/>        
<property name = "ftp.local.dir" value = "${deploy.folder}" />

<!-- WinSCP-->
<property name = "winscp.run" value ="${path.to.root}\tools\WinSCP\WinSCP.com"/>

<target description="Copy to the FTP server" name="ftp.copy">
    <exec program="${winscp.run}">
        <arg value="/command" />
        <arg value="option batch abort" />
        <arg value="option confirm off" />
        <arg value="option transfer binary" />
        <arg value="open ftp://${ftp.user}:${ftp.password}@${ftp.host}:${ftp.port}" />
        <arg value= '"put ""${ftp.local.dir}"""' />         
        <arg value="close" />
        <arg value="exit" />
    </exec>     
</target>

Have fun!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文