PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ftp_get_option> <ftp_fget
Last updated: Fri, 22 Aug 2008

view this page in

ftp_fput

(PHP 4, PHP 5)

ftp_fputCarga un archivo abierto al servidor FTP

Descripción

bool ftp_fput ( resource $secuencia_ftp , string $archivo_remoto , resource $gestor , int $modo [, int $pos_inicio ] )

ftp_fput() carga los datos desde un apuntador de archivo a un archivo remoto en el servidor FTP.

Lista de parámetros

secuencia_ftp

El identificador de enlace de la conexión FTP.

archivo_remoto

La ruta del archivo remoto.

gestor

Un apuntador de archivo abierto sobre el archivo local. La lectura se detiene al final del archivo.

modo

El modo de transferencia. Debe ser o bien FTP_ASCII o FTP_BINARY.

pos_inicio

Valores retornados

Devuelve TRUE si todo se llevó a cabo correctamente, FALSE en caso de fallo.

Ejemplos

Example #1 Ejemplo de ftp_fput()

<?php

// abrir algun archivo para lectura
$archivo 'somefile.txt';
$da fopen($archivo'r');

// configurar la conexion basica
$id_con ftp_connect($servidor_ftp);

// iniciar sesion con nombre de usuario y contrasenya
$resultado_login ftp_login($id_con$ftp_nombre_usuario$ftp_contrasenya);

// trata de cargar $archivo
if (ftp_fput($id_con$archivo$daFTP_ASCII)) {
    echo 
"Se ha cargado $archivo satisfactoriamente\n";
} else {
    echo 
"Hubo un problema durante la carga de $archivo\n";
}

// cerrar la conexion y el gestor de archivo
ftp_close($id_con);
fclose($da);

?>

Registro de cambios

Versión Descripción
4.3.0 Se añadió pos_inicio .



ftp_get_option> <ftp_fget
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
ftp_fput
jopi paranoid fi
20-May-2008 09:57
When you have your file contents as a string, create temporary stream and use that as a file handle.

<?php

$contents
= "This is a test file\nTesting 1,2,3..";

$tempHandle = fopen('php://temp', 'r+');
fwrite($tempHandle, $contents);
rewind($tempHandle);       

ftp_fput($this->ftp, $filename, $tempHandle, FTP_ASCII);

?>
Charlie Brown
16-Apr-2008 11:19
Fails if destination file exists. Delete first and it works.
info at daniel-marschall dot de
19-Apr-2006 09:04
This is a function i wrote to copy a complete directory to a FTP-Server-folder.

function ftp_uploaddirectory($conn_id, $local_dir, $remote_dir)
{
  @ftp_mkdir($conn_id, $remote_dir);
  $handle = opendir($local_dir);
  while (($file = readdir($handle)) !== false)
  {
    if (($file != '.') && ($file != '..'))
    {
      if (is_dir($local_dir.$file))
      {
        ftp_uploaddirectory($conn_id, $local_dir.$file.'/', $remote_dir.$file.'/');
      }
      else
        $f[] = $file;
    }
  }
  closedir($handle);
  if (count($f))
  {
    sort($f);
    @ftp_chdir($conn_id, $remote_dir);
    foreach ($f as $files)
    {
      $from = @fopen("$local_dir$files", 'r');
      @ftp_fput($conn_id, $files, $from, FTP_BINARY);
    }
  }
}

Example:

$conn_id = @ftp_connect($server);
@ftp_login ($conn_id, $username, $passwort);
ftp_uploaddirectory($conn_id, 'mydirectory/', 'theftpdirectory/');
@ftp_quit($conn_id);

I hope you'll find it useful.
BobFrank <rsfranc at yahoo dot com dot br>
24-Aug-2003 06:10
FTP upload server 2 server
<?php
$FTP_HOST
="ftp.br.geocities.com";
$FTP_USER ="bobfrank";
$FTP_PW   ="mypasswd";
$FTP_ROOT_DIR="/";
$LOCAL_SERVER_DIR  = "images/";
$FTP_DIR = "mydir/";
$handle=opendir($LOCAL_SERVER_DIR);
while ((
$file = readdir($handle))!==false)
{
    if(!
is_dir($file)){
       
$f[]="$file";       
      }
}
closedir($handle);
sort($f);
$count=0;
$mode = FTP_BINARY; // or FTP_ASCII
$conn_id = ftp_connect($FTP_HOST);
if(
ftp_login($conn_id, $FTP_USER, $FTP_PW)){
    print
"from: ".$LOCAL_SERVER_DIR."<br>";
    print
"to: ".$FTP_HOST.$FTP_ROOT_DIR.$FTP_DIR."<br>";
   
ftp_pwd($conn_id);
   
ftp_mkdir($conn_id,$FTP_DIR);
   
ftp_chdir($conn_id,$FTP_DIR);
    foreach(
$f as $files) {
       
$from = fopen($LOCAL_SERVER_DIR.$files,"r");    
        if(
ftp_fput($conn_id, $files, $from, $mode)){
           
$count +=1;
            print
$files."<br>";
        }
    }
   
ftp_quit($conn_id);
}
print
"upload : $count files.";
?>
darian lassan at yahoo de
04-Feb-2003 07:00
If you want to pass a string containing the filename as source and not a resource handle use ftp_put() instead. Trivial but not mentioned here.

ftp_get_option> <ftp_fget
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites