User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,480 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,166 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 299 | Replies: 2
Reply
Join Date: May 2008
Posts: 1
Reputation: rahul10721 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rahul10721 rahul10721 is offline Offline
Newbie Poster

Deleting A file on the FTP via php script

  #1  
May 10th, 2008
I need a working code for deleting an uploded file on the ftp server.I do have a script but it dosn't work..


<?php

// set up the settings
$file = 'old.txt';

$ftp_server = someone.net';
$ftpuser = 'user';
$ftppass = 'passwd';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);

// try to delete $file
if (ftp_delete($conn_id, $file)) { // the ftp function
echo "$file deleted successful\n";
} else {
echo "could not delete $file\n";
}

// close the connection
ftp_close($conn_id);

?>



this code is not able to find the old.txt,but this file is placed in the same directory where the script is located.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
robothy robothy is offline Offline
Light Poster

Re: Deleting A file on the FTP via php script

  #2  
May 10th, 2008
Hi,

Surely the FTP will map your public_html folder, within which will be your PHP scripts. So can you not simply use the unlink function in PHP?

Sorry if I am over simplifying the problem.

R
Reply With Quote  
Join Date: Sep 2005
Posts: 689
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 6
Solved Threads: 41
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Deleting A file on the FTP via php script

  #3  
May 10th, 2008
Originally Posted by robothy View Post
Hi,

Surely the FTP will map your public_html folder, within which will be your PHP scripts. So can you not simply use the unlink function in PHP?

Sorry if I am over simplifying the problem.

R


unlink() function in PHP will be run under the Apache user, however, you can have FTP run under any user as long as you have their authentication details.

ie: If you use unlink(), it will not unlink from FTP session, it will unlink from the PHP process.

this code is not able to find the old.txt,but this file is placed in the same directory where the script is located.

When you log into FTP it will most likely put you into the user directory of the user that authenticates, or keep you in the public ftp directory (may also depend on the ftp application running on the server and settings). You will not be placed into the directory your script is in.

So you will have to log in via FTP, then change the directory to the folder your script is in.

http://www.php.net/manual/en/function.ftp-chdir.php
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC