PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<ftp_fgetftp_get_option>
view the version of this page
Last updated: Thu, 21 Aug 2003

ftp_fput

(PHP 3>= 3.0.13, PHP 4 )

ftp_fput -- Uploads from an open file to the FTP server

Description

bool ftp_fput ( resource ftp_stream, string remote_file, resource handle, int mode [, int startpos])

ftp_fput() uploads the data from the file pointer handle until the end of the file is reached. The results are stored in remote_file on the FTP server. The transfer mode specified must be either FTP_ASCII or FTP_BINARY.

Example 1. ftp_fput() example

<?php

// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');

// connect to the server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to upload the file
if(ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler    
ftp_close($conn_id);
fclose($fp);

?>

Note: The startpos parameter was added in PHP 4.3.0.

Returns TRUE on success or FALSE on failure.

See also ftp_put(), ftp_nb_fput(), and ftp_nb_put().



add a note add a note User Contributed Notes
ftp_fput
BobFrank <rsfranc at yahoo dot com dot br>
24-Aug-2003 11: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
05-Feb-2003 02: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.
jeff at procata dot com
07-Nov-2001 09:45
You might need to issue a rewind() on the file pointer if you have just written to the file.

For example:

$fp = tmpfile();
fwrite($fp, $FileContent);
rewind($fp);

ftp_fput($ftp, $fsPath, $fp, FTP_BINARY);

<ftp_fgetftp_get_option>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST