<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[用curl实现自动上传下载 ]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 19 Nov 2008 02:57:58 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	写了一个批量自动上传下载文件的小工具。 特点：<br/><br/>&nbsp;&nbsp; 1. 文件名中可包含日期如TEST20070212.txt<br/>&nbsp;&nbsp; 2. 可多次运行，不会重复处理已成功的条目<br/>&nbsp;&nbsp; 3. 配置方便，异常处理完善<br/><br/>想来今后或许还用得上，所以放在这里晒一下。好不好用各位试下就知道了。 myftp.sh内容如下：<br/><br/><br/><div class="code">#!/bin/bash<br/>#Author: Robin Guo<br/><br/>DATE_YYYYMMDD=`date +%Y%m%d`<br/>DATE_YYMMDD=`date +%y%m%d`<br/>DATE_YYYY_MM_DD=`date +%Y-%m-%d`<br/><br/>#日志文件~/log/YYYYMMDD.LOG<br/>FTP_LOG=~/log/$&#123;DATE_YYYYMMDD&#125;.LOG<br/><br/>#Function ftp_download<br/>#Example:<br/>#ftp_download ftp://interfs:qwerasdf@10.245.10.245:21/home/interfs/etc/config.test config.test<br/>ftp_download()<br/>&#123;<br/>if &#91; &quot;$#&quot; = &quot;2&quot; &#93;<br/>then<br/>if &#91; -f $2 &#93;<br/>then<br/>#文件已存在，说明上次下载已成功，可跳过<br/>echo &quot;INFO : $2 exists&quot; &#124; tee -a $FTP_LOG<br/>else<br/>echo &quot;FROM : $1&quot; &#124; tee -a $FTP_LOG<br/>echo &quot;TO&nbsp;&nbsp; : $2&quot; &#124; tee -a $FTP_LOG<br/>curl -s -P 21000 --connect-timeout 8 --max-time 60 $1 -o $2 &gt; /dev/null&nbsp;&nbsp;2&gt;&amp;1<br/>CURL_RETCODE=$?<br/>if &#91; &quot;$CURL_RETCODE&quot; = &quot;0&quot; &#93;<br/>then<br/>echo &quot;INFO : downlaod $1 is ok&quot; &#124; tee -a $FTP_LOG<br/>touch $2 &gt; /dev/null 2&gt;&amp;1<br/>else<br/>echo &quot;ERROR: download $1 is failed. curl return ($CURL_RETCODE)&quot; &#124; tee -a $FTP_LOG<br/>rm -f $2 &gt; /dev/null 2&gt;&amp;1<br/>fi<br/>fi<br/>echo &quot;&quot; &#124; tee -a $FTP_LOG<br/>fi<br/>&#125;<br/><br/>#Function ftp_upload<br/>#Example:<br/>#ftp_upload uploadfile.txt ftp://interfs:qwerasdf@10.245.10.245:21/home/interfs/etc/upload.txt<br/><br/>ftp_upload()<br/>&#123;<br/>if &#91; &quot;$#&quot; = &quot;2&quot; &#93;<br/>then<br/>if &#91; -f $1 &#93;<br/>then<br/>if &#91; -f $1.ok &#93;<br/>then<br/>#“文件.ok”存在，说明上次已成功上传，可跳过<br/>echo &quot;INFO : already upload $1&quot; &#124; tee -a $FTP_LOG<br/>else<br/>echo &quot;FROM : $1&quot; &#124; tee -a $FTP_LOG<br/>echo &quot;TO&nbsp;&nbsp; : $2&quot; &#124; tee -a $FTP_LOG<br/>curl -s -P 21000 --connect-timeout 8 --max-time 60 -T $1 $2 &gt; /dev/null&nbsp;&nbsp;2&gt;&amp;1<br/>CURL_RETCODE=$?<br/>if &#91; &quot;$CURL_RETCODE&quot; = &quot;0&quot; &#93;<br/>then<br/>#上传成功，做标记<br/>touch&nbsp;&nbsp;$&#123;1&#125;.ok &gt; /dev/null 2&gt;&amp;1<br/>echo &quot;INFO : upload $1 is ok&quot; &#124; tee -a $FTP_LOG<br/>else<br/>echo &quot;ERROR: upload $1 is failed. curl return ($CURL_RETCODE)&quot; &#124; tee -a $FTP_LOG<br/>fi<br/>fi<br/>else<br/>echo &quot;ERROR: upload failed. $1 not exists.&quot; &#124; tee -a $FTP_LOG<br/>fi<br/>echo &quot;&quot; &#124; tee -a $FTP_LOG<br/>fi<br/>&#125;<br/><br/>date &quot;+%y-%m-%d %H:%M&quot; &#124; tee -a $FTP_LOG<br/><br/>if &#91; &quot;$#&quot; != &quot;1&quot; &#93;<br/>then<br/>echo &quot;Usage: ftp.sh ftp.cfg&quot;<br/>exit 1<br/>fi<br/><br/>FTP_CONFIG=$1<br/>if &#91; -f $FTP_CONFIG &#93;<br/>then<br/>echo &quot;INFO : Config File: $FTP_CONFIG&quot; &#124; tee -a $FTP_LOG<br/>echo &quot;&quot; &#124; tee -a $FTP_LOG<br/>else<br/>echo &quot;ERROR: Config File $FTP_CONFIG not exist&quot; &#124; tee -a $FTP_LOG<br/>exit 1<br/>fi<br/><br/>killall curl &gt; /dev/null 2&gt;&amp;1<br/><br/>#从配置中读取条目<br/>while read V_SYSID V_FILE_NAME V_DIRE V_REMOTE_PATH V_LOCAL_PATH<br/>do<br/>FIRST_CHAR=$&#123;V_SYSID:0:1&#125;<br/>if &#91; &quot;$FIRST_CHAR&quot; != &quot;#&quot; &#93;<br/>then<br/>#展开文件名中的日期段<br/>FILE_NAME=$&#123;V_FILE_NAME&#125;<br/>FILE_NAME=$&#123;FILE_NAME/&#92;$YYYYMMDD&#92;$/$DATE_YYYYMMDD&#125;&nbsp;&nbsp;&nbsp;&nbsp; # $YYYYMMDD$ to 20070120<br/>FILE_NAME=$&#123;FILE_NAME/&#92;$YYMMD&#92;$/$DATEYYMMDD&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # $YYMMDD$ to 070120<br/>FILE_NAME=$&#123;FILE_NAME/&#92;$YYYY-MM-DD&#92;$/$DATE_YYYY_MM_DD&#125; # $YYYY-MM-DD$ to 2007-01-20<br/>if &#91; &quot;$V_DIRE&quot; = &quot;DNLD&quot; &#93;<br/>then<br/>echo &quot;INFO : Download $&#123;FILE_NAME&#125; ... &quot; &#124; tee -a $FTP_LOG<br/>ftp_download $&#123;V_REMOTE_PATH&#125;$&#123;FILE_NAME&#125; $&#123;V_LOCAL_PATH&#125;$&#123;FILE_NAME&#125;<br/>fi<br/>if &#91; &quot;$V_DIRE&quot; = &quot;UPLD&quot; &#93;<br/>then<br/>echo &quot;INFO : Upload $&#123;FILE_NAME&#125;... &quot; &#124; tee -a $FTP_LOG<br/>ftp_upload $&#123;V_LOCAL_PATH&#125;$&#123;FILE_NAME&#125; $&#123;V_REMOTE_PATH&#125;$&#123;FILE_NAME&#125;<br/>fi<br/><br/>fi<br/>done &lt; $FTP_CONFIG</div><br/>典型的配置范例myftp.cfg如下：<br/><br/>#SYSID FILE_NAME DIRECTION(DNLD/UPLD) REMOTE_PATH/ LOCAL_PATH/<br/>0001 010YCDZ$YYYYMMDD$.txt&nbsp;&nbsp; UPLD ftp://user:passwd@10.245.62.226:21/dz/ /home/myftp/whdl/<br/>0002 010YCJZ$YYYYMMDD$.TXT&nbsp;&nbsp; UPLD ftp://user:passwd@10.245.62.226:21/jz/ /home/myftp/whdl/<br/>0003 010YJJS$YYYY-MM-DD$.TXT DNLD ftp://user:passwd@10.245.62.226:21/pk/js/ /home/myftp/whdl/<br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 用curl实现自动上传下载 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>