开发者

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

开发者 https://www.devze.com 2023-04-12 19:10 出处:网络
I开发者_高级运维 am using Phing and right now I am using this code to upload my files to FTP: <target name=\"ftp.upload\">

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!


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


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/


I wrote down a perl script that does it with a svn repository ( http://svnftpdeploy.sourceforge.net/ ... I do not know what I wrote in english)

It requires a local directory to get files from svn, another to to get files from ftp (the changed in the next svn release), a local file for store last uploaded svn release, a local directory to store changed file list from ftp. And it interactively ask for action in case of conflict (someone changed file in server independently from your deploy script).

Now I am switching to phing and git, the hard part would be to manage interactivity, I think I would manage it with -D= for the target deploy (with -Dconflictaction=stop,viewdiff,viewdiffanddeploy,ignore or such a thing).


You can use git-ftp or dandelion to upload just the changes via ftp. I guess it is not so hard to use one of them with phing...


Have you tried using the depends="true" attribute of FtpDeployTask?

If depends is set to true, the task will only update files with a local modification timestamp that is newer than the corresponding timestamp on the server.

Sadly, this doesn't seem to work for me: all files are being transferred.

0

精彩评论

暂无评论...
验证码 换一张
取 消