PHP 8.3.4 Released!

FTP

  • はじめに
  • インストール/設定
  • 定義済み定数
  • FTP 関数
    • ftp_alloc — アップロードされるファイルのためのスペースを確保する
    • ftp_append — ファイルの内容をFTPサーバー上の別のファイルに追加する
    • ftp_cdup — 親ディレクトリに移動する
    • ftp_chdir — FTP サーバー上でディレクトリを移動する
    • ftp_chmod — FTP 経由でファイルのパーミッションを設定する
    • ftp_close — FTP 接続を閉じる
    • ftp_connect — FTP 接続をオープンする
    • ftp_delete — FTP サーバー上のファイルを削除する
    • ftp_exec — FTP サーバー上でのコマンドの実行をリクエストする
    • ftp_fget — FTP サーバーからファイルをダウンロードし、オープン中のファイルに保存する
    • ftp_fput — オープン中のファイルを FTP サーバーにアップロードする
    • ftp_get_option — カレントの FTP 接続での種々の実行時動作を取得する
    • ftp_get — FTP サーバーからファイルをダウンロードする
    • ftp_login — FTP 接続にログインする
    • ftp_mdtm — 指定したファイルが最後に更新された時刻を返す
    • ftp_mkdir — ディレクトリを作成する
    • ftp_mlsd — ディレクトリに存在するファイルの一覧を返す
    • ftp_nb_continue — ファイルの取得/送信を継続する(非ブロッキング)
    • ftp_nb_fget — FTP サーバーからファイルをダウンロードし、オープン中のファイルに保存する(非ブロッキング)
    • ftp_nb_fput — オープン中のファイルを FTP サーバーに保存する(非ブロッキング)
    • ftp_nb_get — FTP サーバーからファイルを取得し、ローカルファイルに書き込む(非ブロッキング)
    • ftp_nb_put — FTP サーバーにファイルを保存する(非ブロッキング)
    • ftp_nlist — 指定したディレクトリのファイルの一覧を返す
    • ftp_pasv — パッシブモードをオンまたはオフにする
    • ftp_put — FTP サーバーにファイルをアップロードする
    • ftp_pwd — カレントのディレクトリ名を返す
    • ftp_quit — ftp_close のエイリアス
    • ftp_raw — FTP サーバーに任意のコマンドを送信する
    • ftp_rawlist — 指定したディレクトリの詳細なファイル一覧を返す
    • ftp_rename — FTP サーバー上のファイルまたはディレクトリの名前を変更する
    • ftp_rmdir — ディレクトリを削除する
    • ftp_set_option — さまざまな FTP 実行時オプションを設定する
    • ftp_site — SITEコマンドをサーバーに送信する
    • ftp_size — 指定したファイルのサイズを返す
    • ftp_ssl_connect — セキュアな SSL-FTP 接続をオープンする
    • ftp_systype — リモート FTP サーバーのシステム型 ID を返す
  • FTP\Connection — FTP\Connection クラス
add a note

User Contributed Notes 2 notes

up
33
tendrid at gmail dot com
12 years ago
For those who dont want to deal with handling the connection once created, here is a simple class that allows you to call any ftp function as if it were an extended method. It automatically puts the ftp connection into the first argument slot (as all ftp functions require).

This code is php 5.3+

<?php
class ftp{
public
$conn;

public function
__construct($url){
$this->conn = ftp_connect($url);
}

public function
__call($func,$a){
if(
strstr($func,'ftp_') !== false && function_exists($func)){
array_unshift($a,$this->conn);
return
call_user_func_array($func,$a);
}else{
// replace with your own error handler.
die("$func is not a valid FTP function");
}
}
}

// Example
$ftp = new ftp('ftp.example.com');
$ftp->ftp_login('username','password');
var_dump($ftp->ftp_nlist());
?>
up
2
asifkhandk at gmail dot com
11 years ago
Upload file to server via ftp.

<?php
$ftp_server
="";
$ftp_user_name="";
$ftp_user_pass="";
$file = "";//tobe uploaded
$remote_file = "";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo
"successfully uploaded $file\n";
exit;
} else {
echo
"There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
?>
To Top