ftp_get

(PHP 3 >= 3.0.13, PHP 4, PHP 5)

ftp_get -- Загружает файл с FTP сервера

Описание

bool ftp_get ( resource ftp_stream, string local_file, string remote_file, int mode [, int resumepos] )

ftp_get() загружает файл удалённый файл с FTP сервера и сохраняет его в локальный файл.

Список параметров

ftp_stream

Идентификатор соединения с FTP сервером

local_file

Путь к локальному файлу (файл будет перезаписан, если уже существует).

remote_file

Путь к удалённому файлу.

mode

Режим передачи. Должен быть либо FTP_ASCII, либо FTP_BINARY.

resumepos

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

Пример 1. Пример использования ftp_get()

<?php

// объявление переменных
$local_file = 'local.zip';
$server_file = 'server.zip';

// установка соединения
$conn_id = ftp_connect($ftp_server);

// вход с именем пользователя и паролем
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// попытка скачать $server_file и сохранить в $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
   echo
"Произведена запись в $local_file\n";
} else {
   echo
"Не удалось завершить операцию\n";
}

// закрытие соединения
ftp_close($conn_id);

?>

Список изменений

ВерсияОписание
4.3.0 добавлен аргумент resumepos.

Смотрите также

ftp_fget()
ftp_nb_get()
ftp_nb_fget()



ftp_get
corey-holzer at nyc dot rr dot com
23-Jan-2004 06:20
The zero size file is not a side effect.  When the ftp_get starts the first thing it does is to create the inode/file which it will stream the data too and that is a zero size file with the nname you specified for the local file.  When the download fails it leaves the file in place.
thivierr at telus dot net
22-Nov-2003 02:25
If you previously downloaded a file before (like a huge web log), and just want to get the remaining portion, do this:

$local_file_size = filesize($local_file_path);
$get_result = ftp_get($conn_id, $local_file_path, $remote_file_path, FTP_BINARY, $local_file_size);

This same code works regardless of wether the local file exists already or not.  You should first test to make sure the local file is not bigger than the remote file.
Logan
05-Sep-2003 05:21
If you want, you can save in any other directory in your hard disk, for example:

ftp_get($ftpstream, "C:\somefile.exe", "somefile.exe", FTP_BINARY);
phpnet at hostar dot com dot ar
09-Jun-2003 11:03
The file transferred will be saved in the folder where the ftp_get function is executed.
So, you will need the write permission in that folder.

In other way, you will obtain a "cant open local file" error.
ramiro at qusarcr dot com
06-Nov-2002 07:36
Keep in mind that ftp_get will overwrite the file on your local machine if it has the same name.

<ftp_get_optionftp_login>
 Last updated: Tue, 15 Nov 2005