CakeFest 2024: The Official CakePHP Conference

ftp_raw

(PHP 5, PHP 7, PHP 8)

ftp_rawFTP サーバーに任意のコマンドを送信する

説明

ftp_raw(FTP\Connection $ftp, string $command): ?array

任意の command を FTP サーバーに送信します。

パラメータ

ftp

FTP\Connection クラスのインスタンス

command

実行したいコマンド。

戻り値

サーバーからの応答を文字列の配列で返します。 失敗した場合は null を返します。 結果の文字列に対して、何の処理も行いません。また、 ftp_raw() はそのコマンドが成功したのかどうかを 判断できません。

変更履歴

バージョン 説明
8.1.0 引数 ftp は、FTP\Connection のインスタンスを期待するようになりました。 これより前のバージョンでは、リソース を期待していました。

例1 ftp_raw() を用いて FTP サーバーに手動でログインする

<?php
$ftp
= ftp_connect("ftp.example.com");

/* ftp_login($ftp, "joeblow", "secret");
を実行するのと同じ意味 */
ftp_raw($ftp, "USER joeblow");
ftp_raw($ftp, "PASS secret");
?>

参考

  • ftp_exec() - FTP サーバー上でのコマンドの実行をリクエストする

add a note

User Contributed Notes 3 notes

up
4
nightwalker85 at gmail dot com
18 years ago
<?
ftp_raw($ftpconn,"CLNT <client>");
?>

Is a good way to let the ftp-server know which client it's dealing with. Guess this can be useful if you're making a homemade ftp-client. Only do this if the ftp-server has responded to FEAT command with a response including CLNT.
up
2
www.bossftp.com
15 years ago
Note that the $command can not contains any illegal character such as \n, \r, \t, or this function will return NULL.

Try using the trim() before calling ftp_raw().

<?php
ftp_raw
($connid, trim($command));
?>
up
1
WebSee.ru
14 years ago
How to realize the possibility of transferring data from one FTP-server to another via FXP?

<?php
// ...

$ansver = ftp_raw($ftp_conn1, 'PASV');

if (
intval($ansver[0]) == 227) {
ftp_raw($ftp_conn2, 'PORT '.substr($ansver[0], $n = strpos($ansver[0], '(') + 1, strpos($m[0], ')', $n) - $n));
ftp_raw($ftp_conn1, 'STOR '.$filename); // need asynchronously (non-blocking)
ftp_raw($ftp_conn2, 'RETR '.$filename);
}
?>
To Top