PHP.mk документација

ftp_nb_put

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.ftp-nb-put.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.ftp-nb-put.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ftp_nb_put

Референца за `function.ftp-nb-put.php` со подобрена типографија и навигација.

function.ftp-nb-put.php

ftp_nb_put

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

ftp_nb_putЧува датотека на FTP сервер (неблокирачки)

= NULL

ftp_nb_put(
         FTP\Connection $ftp,
         string $remote_filename,
         string $local_filename,
         int $mode = FTP_BINARY,
         int $offset = 0
): int|false

ftp_nb_put() Поставува датотека на FTP-серверот

Чува датотека на FTP сервер (неблокирачки) ftp_put() Разликата помеѓу оваа функција и

Параметри

ftp

Еден FTP\Connection instance.

remote_filename

ја зачувува локалната датотека на FTP-серверот.

local_filename

Патеката до далечинската датотека.

mode

Патеката до локалната датотека. FTP_ASCII or FTP_BINARY.

offset

Режимот на пренос. Мора да биде или

Вратени вредности

Патеката до PHP скриптата што треба да се провери. FTP_FAILED or FTP_FINISHED or FTP_MOREDATA, или false при неуспех при отворање на локалната датотека.

Дневник на промени

Верзија = NULL
8.1.0 На ftp параметарот очекува FTP\Connection инстанца сега; претходно, а resource се очекуваше.
7.3.0 На mode Позицијата во далечинската датотека за почеток на поставувањето.

Примери

Пример #1 ftp_nb_put() example

<?php

// Initiate the Upload
$ret = ftp_nb_put($ftp, "test.remote", "test.local", FTP_BINARY);
while (
$ret == FTP_MOREDATA) {

// Do whatever you want
echo ".";

// Continue uploading...
$ret = ftp_nb_continue($ftp);
}
if (
$ret != FTP_FINISHED) {
echo
"There was an error uploading the file...";
exit(
1);
}
?>

е дека оваа функција ја поставува датотеката асинхроно, така што вашата програма може да извршува други операции додека датотеката се поставува. ftp_nb_put()

<?php

// Initiate
$ret = ftp_nb_put($ftp, "test.remote", "test.local",
FTP_BINARY, ftp_size("test.remote"));
// OR: $ret = ftp_nb_put($ftp, "test.remote", "test.local",
// FTP_BINARY, FTP_AUTORESUME);

while ($ret == FTP_MOREDATA) {

// Do whatever you want
echo ".";

// Continue uploading...
$ret = ftp_nb_continue($ftp);
}
if (
$ret != FTP_FINISHED) {
echo
"There was an error uploading the file...";
exit(
1);
}
?>

Види Исто така

  • ftp_nb_fput() - Поставува од отворена датотека на FTP-серверот
  • ftp_nb_continue() - Продолжува со преземање/испраќање датотека (неблокирачки)
  • ftp_put() Пример #2 Продолжување на поставување со
  • ftp_fput() - Вклучува или исклучува пасивен режим

Белешки од корисници 6 белешки

- Поставува датотека на FTP сервер
21 години пред
If you receive an error like:  

Warning:  ftp_nb_put(): Unable to service PORT commands in /path/to/file.php on line 27

verify whether you need to be in PASV mode. You can go into PASV mode by declaring

>  ftp_pasv($cnx,TRUE);
ted at hostleft dot com
21 години пред
When using non blocking functions if you try to disconnect while your non blocking operation is in progress the disconnect command will not work until the operation is not finished.
manu at manux dot org
19 години пред
Don't add a sleep() inside the loop. If you do you will severely slow down the upload.

In my tests, each time through the loop it send about 2.5K, looping about 220 times per second. (Which is very little.)

You won't necessarily get the same numbers as me per loop, but clearly PHP does it's own management of the loop so that you don't consume all the CPU on the server.
WebSee.ru
пред 16 години
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);
}
?>
Ariel asphp at dsgml dot com
19 години пред
Hi, 
I tried to use both ftp_put() and ftp_nb_put() adding the
variable $start = date("Y:m:d h:i:s"); at the begin of the script and the variable $end = date("Y:m:d h:i:s"); at its end, after the file upload function.
With the gprs connection I'm now using and trying to upload a .jpg file of 67,5 kb the time difference between $start and $end was 40 seconds in both cases, so I can suppose that there is no difference between these upload function.
The difference comes if you put anything inside the while ($ftp_upload == FTP_MOREDATA) loop.
I hope this note can help.
Regards
kaiohken1982 at hotmail dot com
20 години пред
I couldn't see this noted anywhere...

ftp_nb_put apparently takes a much much longer time to upload the file than ftp_put (I haven't done any packet sniffing or logging tests to find out why).  I was using a script, nearly identical to the example above, and a 100KB file had only uploaded 3.99KB after about 8 minutes!  The php script naturally timed out before it was complete.

I changed my function to use ftp_put, got rid of the loop to check FTP_MOREDATA (as you will see in the example above), and the same script uploaded 2.2MB within 30 seconds with no other changes.

If you're using this function instead of ftp_put *purely to try to speed up your script* and it's taking a long time, you might want to try ftp_put instead.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.