PHP でセキュアな FTP 操作は、標準では cURL を使うしかありませんが、PHP 5.2.0 である必要があります。 定義済み定数
<?php header( "Content-Type: text/plain" ); header( "pragma: no-cache" ); header( "Expires: Wed, 31 May 2000 14:59:58 GMT" ); header( "Cache-control: no-cache" ); $curl_const = array(); $curl_const[] = CURLOPT_FTP_SSL; $curl_const[] = CURLFTPSSL_NONE; $curl_const[] = CURLFTPSSL_TRY; $curl_const[] = CURLFTPSSL_CONTROL; $curl_const[] = CURLFTPSSL_ALL; print_r($curl_const); ?>
上記コードでは以下のような結果で表示されます
Array
(
[0] => 119
[1] => 0
[2] => 1
[3] => 2
[4] => 3
)
<?php
header( "Content-Type: text/plain" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
// *********************************************************
// ユーザとパスワード
// *********************************************************
$username = 'ユーザ';
$password = 'パスワード';
// *********************************************************
// 対象ファイル
// ログインディレクトリからの相対位置
// ( SSL のサーバーチェックの為、独自ドメインは使えません )
// *********************************************************
$url = 'lightbox.sakura.ne.jp/www/homepage/download/WinOfSql102.zip';
// *********************************************************
// URL
// *********************************************************
$ftp_server = "ftp://" . $username . ":" . $password . "@" . $url;
// *********************************************************
// 開始
// *********************************************************
$ch = curl_init();
// *********************************************************
// デバッグ用の詳しいメッセージを出力
// *********************************************************
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$fpe = fopen("./debug.txt","w");
curl_setopt($ch, CURLOPT_STDERR, $fpe);
// *********************************************************
// サーバーのパス
// *********************************************************
curl_setopt($ch, CURLOPT_URL, $ftp_server);
// *********************************************************
// SSL である事の明示
// *********************************************************
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_ALL); // SSL for all communication or fail
// *********************************************************
// SSL に必要なオプション
// *********************************************************
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2はデフォルト値( 1は7.28.1 以降では使えなくなりました )
// *********************************************************
// ダウンロードされるファイルの保存設定
// *********************************************************
$fp = fopen("./WinOfSql102.zip","w");
curl_setopt($ch, CURLOPT_FILE, $fp);
// *********************************************************
// 実行
// *********************************************************
$result = curl_exec($ch);
// *********************************************************
// 終了
// *********************************************************
curl_close($ch);
// *********************************************************
// 後処理
// *********************************************************
fclose($fp);
fclose($fpe);
if ($data === false) {
print "cURL failed\n";
}
else {
print "OK\n";
}
?>
関連する情報 Curl: ftp.c ignores some SSL errors regardless of the curl_ftpssl setting
|
|
【PHP+通信の最新記事】
- PHP : curl で FTP サーバのファイル一覧( 結果は JSON )
- fake sendmail for windows ってなんで無名なんだ???
- Livedoor の お天気Webサービス API は、JSON のテストするのに重宝しています。
- abraham さんの twitteroauth の TwitterOAuth クラスのメソッド一覧概要
- abraham さんの twitteroauth で Twitter 投稿
- abraham さんの twitteroauth のライセンスは、MIT ライセンスと同文
- PHPからのメール送信
- PHPによるFTPサーバーのデータ一括ダウンロード




























