<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ひろぽっぽれす &#187; pear</title>
	<atom:link href="http://hiropo.co.uk/archives/category/pear/feed" rel="self" type="application/rss+xml" />
	<link>http://hiropo.co.uk</link>
	<description>Web系エンジニアの適当なブログです。どうでも酔いものばかり作ってます。</description>
	<lastBuildDate>Mon, 12 Mar 2012 06:10:01 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>ディレクトリごとFTPでアップロードしてくれるスクリプト &#8211; コマンドラインPHP</title>
		<link>http://hiropo.co.uk/archives/279</link>
		<comments>http://hiropo.co.uk/archives/279#comments</comments>
		<pubDate>Sat, 22 Aug 2009 18:17:30 +0000</pubDate>
		<dc:creator>hirohi</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hiropo.co.uk/?p=279</guid>
		<description><![CDATA[JavaScriptネタばかりで飽きてきたので、PHPネタでも書いてみる。 最近はまっているのは、webアプリケーションを作るためのPHPではなく、コマンドラインでいろいろできるPHPスクリプトを組むことです。 bash &#8230; <a href="http://hiropo.co.uk/archives/279">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>JavaScriptネタばかりで飽きてきたので、PHPネタでも書いてみる。<br />
最近はまっているのは、webアプリケーションを作るためのPHPではなく、コマンドラインでいろいろできるPHPスクリプトを組むことです。</p>
<p>bashでも良いんだけど、やはり物足りないので、（と言ってもそこまで使いこなしていない・・・。）Pythonという選択肢もあるけど、Pythonわかんないので、PHPを使って、ディレクトリごとFTPでアップロードしてくれるスクリプトを書いてみた。</p>
<p>PEARライブラリを使ったソースコードになっているので、このクラスを使う場合、PEARのインストールが必要になってくる。</p>
<p>まずは、型となる ftp_dir_put.class を定義する。<br />
ファイル名は ftp_dir_put.php で保存。</p>
<pre>
&lt;?php

/*****************************************************
*
*  ftp_dir_put.class
*
*  ftpアップロードをディレクトリ単位で実行するクラス
*  Terminal上での実行専用
*
*****************************************************/

require_once &#039;Net/FTP.php&#039;;

class ftp_dir_put {

  /*-------------------------------------
  *  コンストラクタ
  */
  public function ftp_dir_put( $ftp_server, $ftp_user_name, $ftp_user_pass, $remote_dir, $local_dir, $mode ){
    /*-------------------------------------
    *  $target_hostオブジェクトを生成
    */
    $target_host = new Net_FTP( $ftp_server, 21 );

    //ftpサーバに接続
    if( $target_host-&gt;connect( $ftp_server  ) ){

      print $ftp_server.&#039; に接続しました&#039;.&quot;\n&quot;;

      //接続後、ログイン認証
      if( $target_host-&gt;login( $ftp_user_name, $ftp_user_pass ) ){
        print $ftp_server.&#039; にログインしました&#039;.&quot;\n&quot;;
        print $local_dir.&#039; を &#039;.$remote_dir.&#039; にアップロードしています･･･&#039;.&quot;\n&quot;;

        if( $target_host-&gt;putRecursive( $local_dir, $remote_dir, $mode ) ){

          print &#039;アップロードが終わりました&#039;.&quot;\n&quot;;
          if( $target_host-&gt;disconnect() ){
            print &#039;ログアウトしました&#039;.&quot;\n&quot;;
          }
          else{
            print &#039;ログアウトに失敗しました&#039;.&quot;\n&quot;;
          }
        }
        else{
          print &#039;アップロードに失敗しました&#039;.&quot;\n&quot;;
          if( $target_host-&gt;disconnect() ){
            print &#039;ログアウトしました&#039;.&quot;\n&quot;;
          }
          else{
            print &#039;ログアウトに失敗しました&#039;.&quot;\n&quot;;
          }
        }
      }
      else{
        print &#039;ログイン失敗しました&#039;.&quot;\n&quot;;
      }
    }
    else{
      print $ftp_server.&#039; に接続できません&#039;.&quot;\n&quot;;
    }
  }
}

?&gt;
</pre>
<p>そして、この ftp_dir_put.class を newして実行するファイルを作成<br />
ファイル名は、test_host.php とかで保存。</p>
<pre>
&lt;?php

require_once &#039;ftp_dir_put.php&#039;;

function init(){

  /*-------------------------------------
  *  プロパティセット
  */
  $ftp_server = &#039;host_name&#039;;       //ftpサーバーアドレス
  $ftp_user_name = &#039;user_name&#039;;    //ユーザー名
  $ftp_user_pass = &#039;user_pass&#039;;    //パスワード
  $remote_dir = &#039;/&#039;;               //サーバー側ディレクトリパス
  $local_dir = &#039;/var/www/html/&#039;;   //ローカル側ディレクトリパス
  $mode = true;                    //オーバーライド

  /*-------------------------------------
  *  実行オブジェクト
  */
  $test_init = new ftp_dir_put(
    $ftp_server,
    $ftp_user_name,
    $ftp_user_pass,
    $remote_dir,
    $local_dir,
    $mode
  );

}

init();

?&gt;
</pre>
<p>これで、あとはコマンドラインにて、この test_host.php を実行</p>
<pre>
[user@host ~]$ php test_host.php
</pre>
<p>で、あとは勝手にアップロードしてくれる。<br />
PEAR、凄いよ、PEAR。</p>
]]></content:encoded>
			<wfw:commentRss>http://hiropo.co.uk/archives/279/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pearでHTTP_Requestクラスを使うには (1)</title>
		<link>http://hiropo.co.uk/archives/163</link>
		<comments>http://hiropo.co.uk/archives/163#comments</comments>
		<pubDate>Thu, 02 Jul 2009 16:19:21 +0000</pubDate>
		<dc:creator>hirohi</dc:creator>
				<category><![CDATA[pear]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hiropo.co.uk/?p=163</guid>
		<description><![CDATA[phpネイティブだとHTTP_Request通信はソースをいっぱい書かなきゃいけないが、PEAR拡張モジュールを使うことによってかなりラクができる。 ▼参考サイト http://www.phppro.jp/school/ &#8230; <a href="http://hiropo.co.uk/archives/163">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>phpネイティブだとHTTP_Request通信はソースをいっぱい書かなきゃいけないが、PEAR拡張モジュールを使うことによってかなりラクができる。</p>
<p>▼参考サイト</p>
<p>http://www.phppro.jp/school/pear/vol8/1</p>
<p>HTTP_Requestクラスを使うには、下記のコマンドを実行する。</p>
<pre>
[root@host]# pear install HTTP_Request
</pre>
<p>これで晴れてHTTP_Requestが使いまくりである。<br />
リファレンスはまた後日。</p>
]]></content:encoded>
			<wfw:commentRss>http://hiropo.co.uk/archives/163/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

