phpbar.de logo

Mailinglisten-Archive

[php] R: [php] php ftp funktionen

[php] R: [php] php ftp funktionen

info_(at)_ticinonline.net info_(at)_ticinonline.net
Thu, 7 Dec 2000 12:07:53 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0046_01C06046.53CB8D40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

Die anlage kann sicher helfen :-)

ciao patrik


 ============================================
 PPK-webprogramm
 P.Hohl
 6672 Gordevio
 info_(at)_ticinonline.net
 info_(at)_grossalp.ch
 www.grossalp.ch


 free program PHP http://php.ticinonline.net/
 ============================================
 Online Programm - ScreenDesign - Configurazioni
 Server Linux Aziendali
 Programmi cc+ PHP CGI ASP Pyton HTML
============================================
----- Original Message -----
From: Cyrill Schumacher <webmasterbhs_(at)_bluewin.de>
To: <php_(at)_php-center.de>
Sent: Thursday, December 07, 2000 11:43 AM
Subject: Re: [php] php ftp funktionen


> > das heißt dann ich müßte für jede aktion (verz wechseln, kopieren,
> > löschen,..) eine neue verbindung mit ftp_connect usw, aufbauen=
>
> jau !!!!! richtich jeratten !
>
> ftp_connect()
>
> ftp_kwitt()
>
> -kiri
> _______________________
> http://www.php-usertreffs.de
>
>
>
> --
> ** Durchgehend geöffnet: http://www.php-center.de **
> Die PHP-Liste: mailto:php_(at)_php-center.de
> http://infosoc.uni-koeln.de/mailman/listinfo/php
>

------=_NextPart_000_0046_01C06046.53CB8D40
Content-Type: application/octet-stream;
	name="ftp.php3"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ftp.php3"

<?php


function phpftp_top() {
?>
<!-- function phpftp_top -->

PHP FTP Client v1.5







<?
}

/* This is the form used for initially collecting username/passwd */

function phpftp_login() {
	phpftp_top();
?>
<!-- function phpftp_login -->
<p>
<form action=3D"ftp.php3" method=3Dpost>
Login:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name=3D"phpftp_user" type=3D"text">
<p>
Password:&nbsp;&nbsp;
<input name=3D"phpftp_passwd" type=3D"password">
<p>
Directory:&nbsp;
<input name=3D"phpftp_dir" type=3D"text">
<p>
<input type=3D"hidden" name=3D"function" value=3D"dir">
<input type=3D"submit" value=3D"connect">
</form>
<p>
<?
	phpftp_bottom();
}

/* This function does not return TRUE/FALSE - it returns the value of
   $ftp, the current FTP stream. */

function phpftp_connect( $phpftp_user, $phpftp_passwd ) {
	$phpftp_host=3D"localhost";
	$ftp =3D ftp_connect( $phpftp_host );
	if ( $ftp ) {
		if ( ftp_login( $ftp, $phpftp_user, urldecode( $phpftp_passwd ) ) ) {
			return $ftp;
		}
	}
}

function phpftp_list( $phpftp_user, $phpftp_passwd, $phpftp_dir ) {
	phpftp_top();
?>
<!-- function phpftp_list -->
<?
	$ftp =3D _(at)_phpftp_connect( $phpftp_user, $phpftp_passwd );
	if ( ! $ftp  ) {
?>
<strong>FTP login failed!</strong>
<a href=3D"ftp.php3">Start over?</a>
<?
		phpftp_bottom();
	} else {
		if ( ! $phpftp_dir ) {
			$phpftp_dir=3Dftp_pwd( $ftp );
		}
		if ( ! _(at)_ftp_chdir( $ftp, $phpftp_dir ) ) {
?>
<font color=3D"#ff0000"><strong>Can't enter that =
directory!</strong></font><p><p>
<?
			$phpftp_dir=3Dftp_pwd( $ftp );
		}
		echo "<strong>Current directory:</strong> " . $phpftp_dir . "<br>\n";
		if ( $phpftp_dir =3D=3D "/" ) {
			$phpftp_dir=3D"";
		}
?>
<table border=3D0 cellspacing=3D20>
<?
		if ( $contents =3D ftp_nlist( $ftp, "." ) ) {
			$d_i=3D0;
			$f_i=3D0;
			sort($contents);
			for ( $i=3D0; $i < count( $contents ); $i++ ) {
				$file_size =3D ftp_size( $ftp, $contents[$i] );
				if ( $file_size =3D=3D -1 ) {
					$nlist_dirs[$d_i]=3D$contents[$i];
					$d_i++;
				} else {
					$nlist_files[$f_i]=3D$contents[$i];
					$nlist_filesize[$f_i]=3D$file_size;
					$f_i++;
				}
			}
?>
<tr><td>
<font face=3D"courier"><strong>Directories</strong></font><br>
<form action=3D"ftp.php3" method=3Dpost>
<input type=3D"hidden" name=3D"function" value=3D"cd">
<input type=3D"hidden" name=3D"phpftp_user" value=3D"<? echo =
$phpftp_user; ?>">
<input type=3D"hidden" name=3D"phpftp_passwd" value=3D"<? echo =
$phpftp_passwd; ?>">
<input type=3D"hidden" name=3D"phpftp_dir" value=3D"<? echo $phpftp_dir; =
?>">
<select name=3D"select_directory" size=3D"10" width=3D"100">
<?
			for ( $i=3D0; $i < count( $nlist_dirs ); $i++ ) {
				echo "<option value=3D\"" . $nlist_dirs[$i] . "\">"  . =
$nlist_dirs[$i] . "</option>\n";
			}
?>
</select><br>
<input type=3D"submit" value=3D"Enter Directory">
</form>
</td><td>
<font face=3D"courier"><strong>Files</strong></font><br>
<form action=3D"ftp.php3" method=3Dpost>
<input type=3D"hidden" name=3D"function" value=3D"get">
<input type=3D"hidden" name=3D"phpftp_user" value=3D"<? echo =
$phpftp_user; ?>">
<input type=3D"hidden" name=3D"phpftp_passwd" value=3D"<? echo =
$phpftp_passwd; ?>">
<input type=3D"hidden" name=3D"phpftp_dir" value=3D"<? echo $phpftp_dir; =
?>">
<select name=3D"select_file" size=3D"10">
<?
			for ( $i=3D0; $i < count( $nlist_files ); $i++ ) {
				echo "<option value=3D\"" . $nlist_files[$i] . "\">"  .  =
$nlist_files[$i] ."  ($nlist_filesize[$i] bytes)". "</option>\n";
			}
?>
</select><br>
<input type=3D"submit" value=3D"Download File">
</form>
</td></tr>
<?
		} else {
?>
<p><font color=3D"#ff0000"><strong>Directory empty or not =
readable</strong></font><p>
<?
		}
?>
</table>
<p>
<form action=3D"ftp.php3" method=3Dpost>
<?
		$cdup=3Ddirname( $phpftp_dir );
		if ( $cdup =3D=3D "" ) {
			$cdup=3D"/";
		}
?>
<input type=3D"hidden" name=3D"function" value=3D"dir">
<input type=3D"hidden" name=3D"phpftp_user" value=3D"<? echo =
$phpftp_user; ?>">
<input type=3D"hidden" name=3D"phpftp_passwd" value=3D"<? echo =
$phpftp_passwd; ?>">
<input type=3D"hidden" name=3D"phpftp_dir" value=3D"<? echo $cdup; ?>">
<input type=3D"submit" value=3D"Go up one directory">
</form>
<p>
<form enctype=3D"multipart/form-data" action=3D"ftp.php3" method=3Dpost>
<input type=3D"hidden" name=3D"max_file_size" value=3D"1000000">
<input type=3D"hidden" name=3D"phpftp_user" value=3D"<? echo =
$phpftp_user; ?>">
<input type=3D"hidden" name=3D"phpftp_passwd" value=3D"<? echo =
$phpftp_passwd; ?>">
<input type=3D"hidden" name=3D"phpftp_dir" value=3D"<? echo $phpftp_dir; =
?>">
<input type=3D"hidden" name=3D"function" value=3D"put">
<input type=3D"submit" value=3D"Upload this:">
<input name=3D"userfile" type=3D"file">
</form>
<p>
<form action=3D"ftp.php3" method=3Dpost>
<input type=3D"hidden" name=3D"function" value=3D"mkdir">
<input type=3D"hidden" name=3D"phpftp_user" value=3D"<? echo =
$phpftp_user; ?>">
<input type=3D"hidden" name=3D"phpftp_passwd" value=3D"<? echo =
$phpftp_passwd; ?>">
<input type=3D"hidden" name=3D"phpftp_dir" value=3D"<? echo $phpftp_dir; =
?>">
<input type=3D"submit" value=3D"Make subdirectory:">
<input name=3D"new_dir" type=3D"text">
<?
		ftp_quit( $ftp );
		phpftp_bottom();
	}
}

function phpftp_cd( $phpftp_user, $phpftp_passwd, $phpftp_dir, =
$select_directory ) {
?>
<!-- function phpftp_cd -->
<?
	$new_directory=3D$phpftp_dir . "/" . $select_directory;
	phpftp_list( $phpftp_user, $phpftp_passwd, $new_directory );
}

function phpftp_mkdir( $phpftp_user, $phpftp_passwd, $phpftp_dir, =
$new_dir ) {
?>
<!-- function phpftp_mkdir -->
<?
	$ftp =3D _(at)_phpftp_connect( $phpftp_user, $phpftp_passwd );
	if ( $phpftp_dir =3D=3D "" ) {
		$phpftp_dir=3D"/";
	}
	if ( ! $ftp ) {
		_(at)_ftp_quit( $ftp );
		phpftp_top();
?>
<font color=3D"#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href=3D"ftp.php3">Start over?</a>
<?
		phpftp_bottom();
	} else {
		$dir_path =3D $phpftp_dir . "/" . $new_dir;
		_(at)_ftp_mkdir( $ftp, $dir_path );
		_(at)_ftp_quit( $ftp );
		phpftp_list( $phpftp_user, $phpftp_passwd, $phpftp_dir );
	}
};
=09

function phpftp_get( $phpftp_user, $phpftp_passwd, $phpftp_dir, =
$select_file ) {
	$ftp =3D _(at)_phpftp_connect( $phpftp_user, $phpftp_passwd );
	if ( $phpftp_dir =3D=3D "" ) {
		$phpftp_dir=3D"/";
	}
	if ( ( ! $ftp ) || ( ! _(at)_ftp_chdir( $ftp, $phpftp_dir ) ) ) {
		_(at)_ftp_quit( $ftp );
		phpftp_top();
?>
<font color=3D"#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href=3D"ftp.php3">Start over?</a>
<?
		phpftp_bottom();
	} else {
		srand((double)microtime()*1000000);
		$randval =3D rand();
		$tmpfile=3D"/home/tmp/" . $select_file . "." . $randval;
		if ( ! ftp_get( $ftp, $tmpfile, $select_file, FTP_BINARY ) ) {
			ftp_quit( $ftp );
			phpftp_top();
?>
<font color=3D"#ff0000"><strong>FTP get failed!</strong></font><p><p>
<a href=3D"ftp.php3">Start over?</a>
<?
			phpftp_bottom();
		} else {
			ftp_quit( $ftp );
			header( "Content-Type: application/octet-stream" );
			header( "Content-Disposition: attachment; filename=3D" . $select_file =
);
			readfile( $tmpfile );
		}
		_(at)_unlink( $tmpfile );
	}
}

function phpftp_put( $phpftp_user, $phpftp_passwd, $phpftp_dir, =
$userfile, $userfile_name ) {
	srand((double)microtime()*1000000);
	$randval =3D rand();
	$tmpfile=3D"/var/tmp/xfers/" . $userfile_name . "." . $randval;
	if ( ! _(at)_copy( $userfile, $tmpfile ) ) {
		phpftp_top();
?>
<font color=3D"#ff0000"><strong>Upload failed!  Can't create temp =
file?</strong></font>
<p><p>
<a href=3D"ftp.php3">Start over?</a>
<?
		phpftp_bottom();
	} else {
		if ( ! $ftp =3D _(at)_phpftp_connect( $phpftp_user, $phpftp_passwd ) ) {
			unlink( $tmpfile );
			phpftp_top();=20
?>
<font color=3D"#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href=3D"ftp.php3">Start over?</a>
<?
			phpftp_bottom();
		} else {
			ftp_chdir( $ftp, $phpftp_dir );
			ftp_put( $ftp, $userfile_name, $tmpfile, FTP_BINARY );
			ftp_quit( $ftp );
			unlink( $tmpfile );
			phpftp_list( $phpftp_user, $phpftp_passwd, $phpftp_dir );
		}
	}
}

switch( $function ) {
	case "dir";
		phpftp_list( $phpftp_user, $phpftp_passwd, $phpftp_dir );
		break;
	case "cd";
		phpftp_cd( $phpftp_user, $phpftp_passwd, $phpftp_dir, =
$select_directory );
		break;
	case "get";
		phpftp_get( $phpftp_user, $phpftp_passwd, $phpftp_dir, $select_file );
		break;
	case "put";
		phpftp_put( $phpftp_user, $phpftp_passwd, $phpftp_dir, $userfile, =
$userfile_name );
		break;
	case "mkdir";
		phpftp_mkdir( $phpftp_user, $phpftp_passwd, $phpftp_dir, $new_dir );
		break;
	case "";
		phpftp_login();
		break;
}
=20
?>


------=_NextPart_000_0046_01C06046.53CB8D40--



php::bar PHP Wiki   -   Listenarchive