Net_FTP::put() – upload a file to the FTP server.


require_once 'Net/FTP.php';

mixed Net_FTP::put ( string $local_file , string $remote_file , bool $overwrite = false , int $mode = null )


This uploads a file to the FTP server from the computer your script runs on.


  • string $local_file - The source file you'd like to upload. You can specify this with either an absolute path or a path relative to the scripts directory. (Beware: The script directory is determined by the called script, if you use includes!)

  • string $remote_file - The path (including filename) you'd like to upload to. This could either be an absolute or relative path to a file (not a directory! see: Net_FTP::putRecursive()).

  • bool $overwrite = false - Whether to overwrite the remote file, if it exists or not. If not set the file will not be overwritten.

  • int $mode = null - This has to be one of the constants FTP_ASCII or FTP_BINARY. If not specified, the class will try to determine the mode from the file extension (from extensions.ini) or fall back to the standard transfer mode (attribute).

Return value

mixed - true on success, otherwise PEAR::Error.


Several errors may be returned by put. The errornumber is unspecific (until now) and will not tell you anything about the errormessage. Possible errors are:

Possible PEAR_Error values
Error message Description Solution
Local file '$local_file' does not exist. The local file you specified does not exist. Correct the local file path.
Remote file '$remote_file' exists and may not be overwriten. The specified remote file exists but may not be overwritten. Maybe you don't have the permission to overwrite the file. Check the filepermissions.
File '$local_file' could not be uploaded to '$remote_file'. The upload of the local file failed. This may have several reasons: Maybe the local file does not exist or the remote directory you wanted to upload to does not exist or is not writeable.


This function can not be called statically.


Using put()



download a file to the computer your script runs on. (Previous) download a whole directory to the computer your script runs on. (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.