ftp_nb_put
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
ftp_nb_put — 儲存一個檔案至 FTP 伺服器(non-blocking)
說明
   ftp_nb_put(
resource
string
string
int
int
): int
  resource
$ftp_stream,string
$remote_file,string
$local_file,int
$mode = FTP_BINARY,int
$startpos = 0): int
   ftp_nb_put() 函式用來把本地檔案 local_file
   儲存到 FTP 伺服器上由 remote_file 參數指定的路徑。
  
與函式 ftp_put() 不同的是,此函式上傳檔案的時候採用的是非同步傳輸模式,也就意味著在檔案傳送的過程中,你的程式可以繼續幹其它的事情。
參數
- 
ftp_stream
- 
      FTP 連線的鏈接識別符號。 
- 
remote_file
- 
      遠端檔案路徑。 
- 
local_file
- 
      本地檔案路徑。 
- 
mode
- 
      傳輸模式選擇,可選參數為 FTP_ASCII(文字模式)或FTP_BINARY(二進制模式)。
- 
startpos
- 
      指定傳輸開始的位置,用來續傳支援。 
返回值
   返回 FTP_FAILED 或 FTP_FINISHED
   或 FTP_MOREDATA。
  
更新日誌
| 版本 | 說明 | 
|---|---|
| 7.3.0 | mode參數為可選,之前版本中為必填。 | 
範例
示例 #1 ftp_nb_put() 示例
<?php
// 初始化
$ret = ftp_nb_put($my_connection, "test.remote", "test.local", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
   
   // 可以同時干其它事
   echo ".";
   // 繼續上傳...
   $ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
   echo "上傳過程中發生錯誤...";
   exit(1);
}
?>
示例 #2 使用 ftp_nb_put() 來續傳檔案
<?php
// 初始化
$ret = ftp_nb_put($my_connection, "test.remote", "test.local", 
                      FTP_BINARY, ftp_size("test.remote"));
// 另一種寫法: $ret = ftp_nb_put($my_connection, "test.remote", "test.local", 
//                           FTP_BINARY, FTP_AUTORESUME);
while ($ret == FTP_MOREDATA) {
   
   // 可以同時干其它事情
   echo ".";
   // 繼續上傳...
   $ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
   echo "上傳過程中發生錯誤...";
   exit(1);
}
?>
參見
- ftp_nb_fput() - 將檔案儲存到 FTP 伺服器 (非阻塞)
- ftp_nb_continue() - 連續獲取/發送檔案(以不分塊的方式 non-blocking)
- ftp_put() - 上傳檔案到 FTP 伺服器
- ftp_fput() - 上傳一個已經打開的檔案到 FTP 伺服器