Something that isn't mentioned above is that although ftp_ssl_connect may be available and will return an FTP stream it may not be usable. Take the following code (FTP login credentials are obviously set elsewhere):
<?php
var_dump(function_exists('ftp_ssl_connect'));
if(function_exists('ftp_ssl_connect'))
{
$ftp_connection = @ftp_ssl_connect($this->ftp_host);
}
else
{
$ftp_connection = @ftp_connect($this->ftp_host);
}
var_dump($ftp_connection);
if($ftp_connection)
{
ftp_login($ftp_connection, $this->ftp_user, $this->ftp_password);
}
// output: bool(true) resource(71) of type (FTP Buffer)
?>
From this you'd assume everything would work, ftp_ssl_connect is available and you have a connection. However, once you get to ftp_login, you could get this:
Warning [2] ftp_login() [function.ftp-login]: AUTH not understood
This is because the server is not configured to understand the encrypted details, even though the function is available and an SSL-FTP stream was opened.
If you are trying to use ftp_ssl_connect make sure you check if you can login after using it, and if not, connect again with standard ftp_connect.
Hope this is of use.
ftp_ssl_connect
(PHP 4 >= 4.3.0, PHP 5)
ftp_ssl_connect — セキュアな SSL-FTP 接続をオープンする
説明
$host
[, int $port = 21
[, int $timeout = 90
]] )
ftp_ssl_connect() は、指定した
host への明示的な SSL-FTP 接続をオープンします。
注意: この関数が存在しないことがあるのはなぜですか?
ftp_ssl_connect() が使えるのは、 ftp モジュールおよび OpenSSL サポートが静的に PHP に組み込まれている場合のみです。 つまり、Windows 版の PHP 公式ビルドではこの関数は使えないということです。 この関数を Windows で使いたい場合は、PHP バイナリを自分でコンパイルしなければなりません。
注意:
ftp_ssl_connect() は、sFTP で使うための関数ではありません。 PHP で sFTP を使うには ssh2_sftp() を参照ください。
パラメータ
-
host -
FTP サーバーのアドレス。このパラメータには、最後のスラッシュや 先頭の ftp:// をつけてはいけません。
-
port -
portパラメータは別のポートに接続することを 指定します。これを省略するか 0 にした場合、デフォルトの FTP ポート、 つまり 21 が使用されます。 -
timeout -
このパラメータは、以降の全てのネットワーク処理の タイムアウトを指定します。省略された場合の デフォルト値は、90 秒となります。timeout は、 ftp_set_option() および ftp_get_option() でいつでも変更および取得可能です。
返り値
成功した場合に SSL-FTP ストリーム、エラー時に FALSE を返します。
変更履歴
| バージョン | 説明 |
|---|---|
| 5.2.2 |
この関数は、SSL 接続を使用できないときに FALSE を返すようになりました。
これまでは、SSL ではない接続に移行していました。
|
例
例1 ftp_ssl_connect() の例
<?php
// SSL 接続を確立する
$conn_id = ftp_ssl_connect($ftp_server);
// ユーザー名とパスワードでログインする
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
echo ftp_pwd($conn_id); // /
// SSL 接続を閉じる
ftp_close($conn_id);
?>
Since ftp_ssl_connect() requires SSL compiled into PHP, Windows users will need to compile their own PHP this way or download it from another source. Here's one such (and trusted) source:
* http://ftp.emini.dk/pub/php/win32/openssl/
