upload file with FTP using nant
Asked Answered
L

6

10

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.

Leigha answered 7/5, 2010 at 20:52 Comment(0)
P
5

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.

Primero answered 9/5, 2010 at 6:46 Comment(0)
K
4

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
Kerwon answered 23/10, 2012 at 3:17 Comment(0)
A
3

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.

Aquarium answered 22/1, 2012 at 17:38 Comment(2)
your blog is 404'ing on an internal call to a twitter pageKerwon
The link has been fixed. Thanks for flagging up.Aquarium
I
3

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.

Iaria answered 4/3, 2012 at 12:17 Comment(0)
S
2

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>
Stumper answered 9/8, 2010 at 16:20 Comment(3)
Note that this appears to require the NAnt FTP Task published here: spinthemoose.com/~ftptaskGarner
@Garner the above link is broken, gives a 404.Iaria
github.com/davidalpert/NAntFTPTask/blob/master/Tasks/ftptask.cs is a more current link, blog.streamlinelogic.ca/2008/03/nant-ftp-task.html is good walk-through.Warble
W
1

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!

Whittaker answered 15/3, 2013 at 3:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.