// Delete a file via FTP
function deleteFileViaFTP($ftpServer, $user, $password, $ftpDir, $ftpFile) {
    
    $error = FALSE;
    
    // Open connection to FTP port
    $ftp = fsockopen($ftpServer,21);

    $foo = fgets($ftp);
    if (!ereg("^220*", $foo)) { $error = "*** Error! FTP service not ready
***\r\n"; }

    // Submit user name and password

    fputs($ftp,"USER $user\r\n");

    $foo = fgets($ftp);
    if (!ereg("^331*", $foo)) { $error = "*** Error! USER commend
unsuccessful ***\r\n"; }
    

    fputs($ftp,"PASS $password\r\n");

    $foo = fgets($ftp);
    if (!ereg("^230*", $foo)) { $error = "*** Error! PASS command
unsuccessful ***\r\n"; }

    // Change to the proper directory
    fputs($ftp,"CWD $ftpDir\r\n");
    $foo = fgets($ftp);
    if (!ereg("^250*", $foo)) { $error = "*** Error! CWD command
unsuccessful ***\r\n"; }

    // Delete the file
    fputs($ftp,"DELE $ftpFile\r\n");

    $foo = fgets($ftp);
    if (!ereg("^250*", $foo)) { $error = "*** Error! DELEte command
unsuccessful\r\n"; }

    // Wrap it up
    fputs($ftp,"QUIT\r\n");

    $foo = fgets($ftp);
    if (!ereg("^221*", $foo)) { $error = "*** Error! FTP service closed
abnormally *** \r\n"; }

    fclose($ftp);

    // Return TRUE if the file has been deleted
    $fileUri = "ftp://$user:$password@;$ftpServer/$ftpDir/$ftpFile";
    $fp = @fopen($fileUri, "r");
    if (!$fp) { return TRUE; } else { return FALSE; }
}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to