Jump to content

FTP deleting Problem


sheac

Recommended Posts

I'm having problems deleting a file using FTP, but its not just any problem. everything with the FTP code works properly, i can delete other files but i am having problems deleting a specific file. heres the problem. the file is being accessed by the server (open for writting all the time) and my problem is, i am trying to download this file once a day and have the script delete the file, so that after deletion (cant rename either btw), it will start a new file and keep writting so that the data that is being written will be new the next day so that i don't get repeat data. i CAN delete/rename this file no problem VIA filezilla, but when i try to have the ftp script delete/rename it, it fails every time. i have tried everything and it just doesn't make sense to me why filezilla can delete it, and the script cannot when essentially they are the same type of connection and sending the same commands, (or i believe they are).

 

if i cannot delete it, i want to at least figure out how to read data to a certain point, and redownload/reread it again starting where i left off again, so i do not get any duplicate data. is there any commands passed through FTP that can force delete/rename (prefer rename but any is good right now). any help? this problem has stopped me in my tracks and is making the entire script i wrote completely useless without this functionality to do it on its own without me manually deleting/renaming it.

Link to comment
https://forums.phpfreaks.com/topic/130343-ftp-deleting-problem/
Share on other sites

because this script is going to run once a day every day, to collect new data from the file and process it. its suposeto rename the current file, download it, process the data, then delete the local file and delete the renamed file on the server, so that the program that is writting the file, will create a new instance of the file and enter all new data.

 

the script is running on a webserver, and FTP'ing to a standard FTP on an entirely different server, and renaming/deleting the file on that remote server.

Link to comment
https://forums.phpfreaks.com/topic/130343-ftp-deleting-problem/#findComment-676212
Share on other sites

heres the code that i have written for it currently, took out all of the useless stuff

 

<?php

set_time_limit(0);

echo "<pre>";                    
$ftp_server 	= "***.***.***.***";//
$ftp_user 		= "*******";//
$ftp_pass 		= "*******";//

$local_file		= "games_mp.log";
$remote_file 	= "/games_mp.log";
$newname_file 	= "/games_mp_BAK.log";

//mysql
$mysql_host 	= "localhost";
$mysql_user 	= "root";
$mysql_pass 	= "";
$mysql_db 		= "data";

$db = dbConnect();

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server\n"); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    ftp_pasv($conn_id, true);
    echo "Connected as $ftp_user@$ftp_server\n";

if (ftp_rename($conn_id, $remote_file, $newname_file)) {
    if (save_file($conn_id, $newname_file, $local_file)) {
        if (ftp_delete($conn_id, $newname_file)) {
            
            echo "File $remote_file Deleted Successfully\n-----------------------------------------------\n\n";
            
            $farray = file($local_file);

            foreach ($farray as $key => $value) {
				//DATA PROCESSING
            }
        }
        else {
            echo "File delete failed\n";
        }
    }
}
else {
	echo "File rename failed\n";
}
} else {
    echo "Couldn't connect as $ftp_user\n";
}

// close the connection
ftp_close($conn_id);  
echo "</pre>"; 
?>

Link to comment
https://forums.phpfreaks.com/topic/130343-ftp-deleting-problem/#findComment-676731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.