Così?
Codice PHP:
<?
error_reporting(E_ALL);
//FTP
//Connect to the FTP server
$ftpstream = ftp_connect('localhost');
//Login to the FTP server
$login = ftp_login($ftpstream, 'user', 'pass');
if($login) { //We are now connected to FTP server.
//Create a directory on your website and set permission where needed
ftp_mkdir($ftpstream, $destpath);
ftp_site($ftpstream,"CHMOD 0777 $destpath");
$file = $sourcepath . 'index.php';
$fp = fopen($file, 'r');
//Upload the temporary file to server
ftp_fput($ftpstream, $file, $fp, FTP_ASCII);
}
//Close FTP connection
ftp_close($ftpstream);