Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phing - Deploy with FTP but only overwrite when size has changed

Tags:

ftp

phing

I am using Phing and right now I am using this code to upload my files to FTP:

<target name="ftp.upload">
    <echo>Uploading files to FTP</echo>
    <ftpdeploy 
        host="${ftp.destination.host}"
        port="${ftp.destination.port}"
        username="${ftp.destination.username}"
        password="${ftp.destination.password}"
        dir="${ftp.destination.dir}"
        mode="${ftp.destination.mode}">
       <fileset refid="TheFiles" />
    </ftpdeploy>
    <echo>FTP Upload Finished!</echo>
</target>

It takes a long time to load, and I have a lot of images - so every time I make a small text change, I don't want it to re-upload everything. Is there a way to detect which files has been changed and only upload those?

Thanks!

like image 903
Drew Avatar asked Oct 11 '11 15:10

Drew


2 Answers

This is a little late ... but you CAN actually do this with Phing. This requires a few steps:

Define a date property to go off from. This will be necessary at the end when you're saving last build date for future builds

< tstamp>
  < format property="builddate" pattern="%m/%d/%Y"  />
  < format property="buildtime" pattern="%I:%M %p" />
< /tstamp>

Define lastbuilddate property. Define it to something way back. Then include a file (will be created at the end of your run) with the same property. If file exists (2nd run and after), it will override the setting you defined with whatever the last date was

< property name="lastbuilddate" value="01/01/1970 12:00 AM" />
< property file="$.\lastbuild.properties" override="true"/>

Include date task in your fileset definition. That specifies to only pick files that have last modified date AFTER your last build date

< fileset id="TheFiles" > < date datetime="${lastbuilddate}" when="after"/> < / fileset>

Run your ftp for the TheFiles fileset

Update the lastbuild.properties file with the latest run date. Noticed that we're using date/time properties defined initially.

    < echo msg="lastbuilddate=${builddate} ${buildtime}" file="$./lastbuild.properties" append="false" />

Every time you run your target, it will only ftp files that were changed since the date specified in lastbuilddate property

like image 184
Alexey Gerasimov Avatar answered Sep 24 '22 13:09

Alexey Gerasimov


I'm afraid there's no way to achieve this using FTP unless YOU maintain some kind of list of modified files. So you'd be better off using rsync. There's a solution already available for phing: http://blog.fedecarg.com/2008/07/21/filesynctask-using-phing-to-synchronize-files-and-directories/

like image 41
poisson Avatar answered Sep 22 '22 13:09

poisson