PHP: FTP functions - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousfribidi_log2visftp_async_continuenext
Last updated: Fri, 30 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

XXXIII. FTP functions

Bevezet�s

The functions in this extension implement client access to file servers speaking the File Transfer Protocol (FTP) as defined in .

K�vetelm�nyek

Az itt le�rt f�ggv�nyek a standard modulban tal�lhat�ak, ami mindig rendelkez�sre �ll.

Telep�t�s

In order to use FTP functions with your PHP configuration, you should add the --enable-ftp option when installing PHP 4, and --with-ftp when using PHP 3.

Fut�sidej� be�ll�t�sok

Ez a kiterjeszt�s semmilyen konfigur�ci�s be�ll�t�sokat nem defini�l.

Er�forr�s t�pusok

This extension uses one resource-type, which is the link-identifier of the ftp-connection.

El�re defini�lt �lland�k

Az itt list�zott �lland�kat ez a kiterjeszt�s defini�lja, �s csak akkor el�rhet�ek, ha az adott kiterjeszt�s be van ford�tva a PHP-be, vagy dinamikusan bet�lt�tt.

FTP_ASCII (integer)

FTP_TEXT (integer)

FTP_BINARY (integer)

FTP_IMAGE (integer)

FTP_TIMEOUT_SEC (integer)

See ftp_set_option() for information.

The following constants were introduced in PHP 4.3.0.

FTP_AUTOSEEK (integer)

See ftp_set_option() for information.

FTP_AUTORESUME (integer)

Automaticly determine resumepos/startpos for get/put request (does only work if FTP_AUTOSEEK is enabled)

FTP_FAILED (integer)

Asynchronous transfer has failed

FTP_FINISHED (integer)

Asynchronous transfer has finished

FTP_MOREDATA (integer)

Asynchronous transfer is still active

P�ld�k

P�lda 1. FTP example

<?php
// set up basic connection
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        die; 
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) { 
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream 
ftp_close($conn_id); 
?>

Tartalom
ftp_async_continue -- Continues retrieving/sending a file asyncronously
ftp_async_fget -- Retrieves a file from the FTP server asynchronly and writes it to an open file
ftp_async_fput -- Stores a file from an open file to the FTP server asyncronly
ftp_async_get -- Retrieves a file from the FTP server asynchronly and writes it to a local file
ftp_async_put -- Stores a file on the FTP server asynchronly
ftp_cdup -- Changes to the parent directory
ftp_chdir -- Changes directories on a FTP server
ftp_close -- Closes an FTP connection
ftp_connect -- Opens up an FTP connection
ftp_delete -- Deletes a file on the FTP server
ftp_exec -- Request execution of a program on the FTP server
ftp_fget -- Downloads a file from the FTP server and saves to an open file
ftp_fput -- Uploads from an open file to the FTP server
ftp_get_option -- Retrieves various runtime behaviours of the current FTP stream
ftp_get -- Downloads a file from the FTP server
ftp_login -- Logs in an FTP connection
ftp_mdtm -- Returns the last modified time of the given file
ftp_mkdir -- Creates a directory
ftp_nlist -- Returns a list of files in the given directory
ftp_pasv -- Turns passive mode on or off
ftp_put -- Uploads a file to the FTP server
ftp_pwd -- Returns the current directory name
ftp_quit -- Closes an FTP connection
ftp_rawlist -- Returns a detailed list of files in the given directory
ftp_rename -- Renames a file on the FTP server
ftp_rmdir -- Removes a directory
ftp_set_option -- Set miscellaneous runtime FTP options
ftp_site -- Sends a SITE command to the server
ftp_size -- Returns the size of the given file
ftp_systype -- Returns the system type identifier of the remote FTP server
User Contributed Notes
FTP functions
add a note about notes
Paul Southworth
16-Mar-2000 08:27

If you are looking for a sketchy sample implementation of an FTP client written in PHP, here is a free one:
[email protected]
24-Apr-2000 06:20

Don't forget that PHP's "filesystem" functions can also work with FTP URLs. In particular, I went and wrote an "ftp_sput" mod to PHP's code to "put" a string to a remote FTP file--and then discovered that with the "fopen" command PHP can already do that!
[email protected]
26-Dec-2000 07:21

Be careful when using ftp_size; some ftp servers report different results depending on whether you have issued a BINARY or ASCII command first. This is a bit of a drag because there appears to be no way of issuing either command with these functions. Instead you must specify the desired transfer type with each ftp_get or ftp_put. Thus for some servers you will get a different number of bytes actually transfered than that reported by the ftp_size function....... Yuk....
[email protected]
02-Aug-2001 05:20


For anybody looking for another example of a PHP FTP client, I have added one to my site. Any feedback is welcome.



[email protected]
02-Nov-2001 06:52

To list a directory with spaces in it, just ftp_chdir to it, and after that call ftp_rawlist with empty string for a second argument.
[email protected]
25-Jan-2002 09:25

In case that your ftp connection using php failed(error msg is ftpbuf()..) add first line before setting up ftp connection:

$conn_id=0;
$conn_id = ftp_connect("$ftp_server");

[email protected]
13-Feb-2002 05:27

connection to a ftp server across proxy

$ftp_server = "proxy"; f.e. 123.456.789.10
$ftp_user_name = "username@ftpserver"; f.e. [email protected]
$ftp_user_pass = "password";

$conn_id = ftp_connect($ftp_server, 2121);
$login_result = ftp_login( $conn_id, $ftp_user_name, $ftp_user_pass );

[email protected]
13-Mar-2002 06:15

you can try using

set_time_limit(0); which will reset the timeout.

to find out what has been completed at at the php script.. you can try using flush(); after echo.. which should display your messages without having to wait for the script to finish loading..

"..I've got this working fine but with slow sites and when sending a batch of
files, the PHP times out! I am using a commercial host so cannot tell them
to increase the PHP timeout and in any case I think that isn't
appropriate.

I am thinking in terms of first opening a connection and then sending each
file with a reload of the page (using a parameter to increment the file to
be sent). This could also give a "progress" indication rather
than freezing.

Is this sensible or can anyone suggest a better approach?

Thanks.

Neil..."

[email protected]
13-May-2002 09:51

Si teneis como respuesta ftpbuf 0 probar esto para conectar:
$conn_id = ftp_connect("127.0.0.1");
Parece absurdo pero me ha funcionado en 2 servidores.

ftpbuf 0 ??? Try:
$conn_id = ftp_connect("127.0.0.1");
It works!!

12-Jun-2002 05:11
gli ftp fatti in PHP sono molto lenti. se ci tenete alla rapidit� programmate un ftp con un altro linguaggio.
add a note about notes
previousfribidi_log2visftp_async_continuenext
Last updated: Fri, 30 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Aug 31 06:19:44 2002 CEST