PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<fribidi_log2visftp_cdup>
view the version of this page
Last updated: Sat, 19 Apr 2003

XXXIII. FTP-Funktionen

FTP ist die Abk�rzung f�r File Transfer Protocol (Datei-�bertragungs-Protokoll).

Die folgenden Konstanten sind definiert, sobald das FTP-Modul benutzt wird: FTP_ASCII und FTP_BINARY.

Beispiel 1. ftp()-Beispiel:

<?php
// Herstellen der Basis-Verbindung
$conn_id = ftp_connect("$ftp_server"); 

// Einloggen mit Benutzername und Kennwort
$login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass"); 

// Verbindung �berpr�fen
if ((!$conn_id) || (!$login_result)) { 
        echo "Ftp-Verbindung nicht hergestellt!";
        echo "Verbindung mit $ftp_server als Benutzer $user nicht m�glich"; 
        die; 
    } else {
        echo "Verbunden mit $ftp_server als Benutzer $user";
    }

// Upload der Datei
$upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY); 

// Upload-Status �berpr�fen
if (!$upload) { 
        echo "Ftp upload war fehlerhaft!";
    } else {
        echo "Datei $source_file auf $ftp_server als $destination_file geschrieben";
    }

// Schlie�en des FTP-Streams
ftp_quit($conn_id); 
?>

Inhaltsverzeichnis
ftp_cdup -- Wechselt in das um eine Ebene h�here Verzeichnis
ftp_chdir -- Verzeichnis-Wechsel auf einem FTP-Server
ftp_chmod -- Setzt die Zugriffsrechte einer Datei �ber FTP
ftp_close -- Closes an FTP connection
ftp_connect -- Stellt eine FTP-Verbindung her
ftp_delete -- L�scht eine Datei auf dem FTP-Server
ftp_exec -- Requests execution of a program on the FTP server
ftp_fget --  L�dt eine Datei vom FTP-Server und speichert sie in eine ge�ffnete, lokale Datei (download)
ftp_fput --  �bertragt eine ge�ffnete Datei auf einen FTP-Server (upload)
ftp_get_option -- Retrieves various runtime behaviours of the current FTP stream
ftp_get --  Liest eine Datei des FTP-Servers und speichert sie lokal (download)
ftp_login -- Anmelden einer FTP-Verbindung (Login)
ftp_mdtm --  Ermittelt die letzte �nderungszeit der angegebenen Datei
ftp_mkdir -- Erzeugt ein Verzeichnis
ftp_nb_continue -- Continues retrieving/sending a file (non-blocking)
ftp_nb_fget -- Retrieves a file from the FTP server and writes it to an open file (non-blocking)
ftp_nb_fput -- Stores a file from an open file to the FTP server (non-blocking)
ftp_nb_get -- Retrieves a file from the FTP server and writes it to a local file (non-blocking)
ftp_nb_put -- Stores a file on the FTP server (non-blocking)
ftp_nlist --  Gibt eine Liste der im angegebenen Verzeichnis enthaltenen Dateien zur�ck
ftp_pasv -- Schaltet den passiven Modus ein oder aus
ftp_put --  �bertr�gt eine Datei auf einen FTP-Server (upload)
ftp_pwd -- Gibt den aktuellen Verzeichnis-Namen zur�ck
ftp_quit -- Schlie�t / beendet eine FTP-Verbindung
ftp_raw -- Sends an arbitrary command to an FTP server
ftp_rawlist --  Gibt eine detaillierte Liste der Dateien in einem angegebenen Verzeichnis zur�ck
ftp_rename -- Benennt eine Datei auf dem FTP-Server um
ftp_rmdir -- L�scht ein Verzeichnis
ftp_set_option -- Set miscellaneous runtime FTP options
ftp_site -- Sendet ein SITE-Kommando zum Server
ftp_size --  Ermittelt die Dateigr�sse einer angegebenen Datei
ftp_ssl_connect -- Opens an Secure SSL-FTP connection
ftp_systype --  Ermittelt den Systemtyp des entfernten FTP-Servers


User Contributed Notes
FTP-Funktionen
add a note
Paul Southworth
16-Mar-2000 09:27

If you are looking for a sketchy sample implementation of an FTP client written in PHP, here is a free one:  
sean at debugs dot org
26-Dec-2000 08: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....
tgrk at hushmail dot com
25-Jan-2002 10: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");

sven at cartell-network dot de
13-Feb-2002 06: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 );

o_sheep at hotmail dot com
13-Mar-2002 07: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..."

will2025 at yahoo dot com
13-May-2002 10: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!!

NOSPAMkent at ioflux dot NOSPAM dot com
20-Sep-2002 12:05

I think what some other posts were trying to say which may need clarification is that in PHP 4.2.3, ftp_connect("myhost.com") was failing most of the time, except it would work like every few minutes.

The fix is that ftp_connect seems to have a bug resolving addresses. If you do:

$hostip = gethostbyname($host);
$conn_id = ftp_connect($hostip);

It seems to solve the problem.
(Other users referred to an ftpbuf() error... not sure what that is, but this should fix it.)

(nospam) bool AT boolsite DOT net
10-Oct-2002 05:19

If you search for FXP (server to server FTP transfer), look at .

This easy to use class is now able to do FXP transfer (v0.6.2) !!!!

Marius at lowvoice dot nl
22-Oct-2002 09:51

if you need to download a  file into a  string instead of into a file try this:

$temp = tmpfile();

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $user, $pass);

$fget_result=ftp_fget($conn_id, $temp, $ftp_file_name, FTP_ASCII);
ftp_quit($conn_id);

rewind ($temp);
$FILE_DATA=fread($temp,$size);
fclose($temp);

you could also do this with fopen() but I found that using this function will keep the connection open even after a fclose()!! So repeating this many times will cause a lot of open ftp-connections.

vikas dot saxena at 4cplus dot com
25-Nov-2002 10:09

While using ftp_rmdir($conn, $userdir);
I'm getting the following error msg.

Unable to find ftpbuf 0

this message is showing where ever $conn is being used.

eric at evilwalrus dot com
11-Jan-2003 05:14

There is no FTP command for the CHMODing of files, so you really have to do it manually using ftp_exec(). I havn't tried this myself but I'm assuming it should work, but here is an example of what I would do.

//After we have connected to the FTP server
//and need to set the perms for a file/dir, use
//this command
if (ftp_exec($ftp_conn, 'chmod 0666 logs/log.txt'))
   echo 'Successfully set permissions for logs/log.txt to 0666';
else
   echo 'Failed to set permissions for logs/log.txt';

Again, I have not tested this, but I assume it would work. Hope that helps.

php dot net at thedrewerys dot com
08-Feb-2003 10:25

To chmod, you need to use ftp_site instead of ftp_exec.

In the example above,
ftp_exec($ftp_conn, 'chmod 0666 logs/log.txt')
should be
ftp_site($ftp_conn, 'chmod 0666 logs/log.txt')

arjenjb dot wanadoo dot nl
09-Mar-2003 05:29

Check for a FTP server written in PHP.
Supports Passive and Active FTP, and all other standard FTP commands as decribed in RFC959.

add a note

<fribidi_log2visftp_cdup>
 Last updated: Sat, 19 Apr 2003
show source | credits | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: /
Last updated: Wed May 14 01:12:44 2003 CEST