can not delete file from the FTP server,need help

Thread Solved

Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

can not delete file from the FTP server,need help

 
0
  #1
Nov 24th, 2008
n the following program i have the error
Warning: ftp_delete() [function.ftp-delete]: Access is denied. in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 89
could not delete wilbourn/ftptest/t.DOC





  1. <?php
  2.  
  3. //Move or Upload Folder Using PHP FTP Functions
  4. function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
  5.  
  6. echo"$_user_name <br/>";
  7. echo"$_user_pass <br/>";
  8. echo" directories are : <br/>";
  9. echo"$local_dir<br/>";
  10. echo"$remote_dir <br/>";
  11.  
  12.  
  13.  
  14. // set up basic connection
  15. $_conn_id = ftp_connect($_server);
  16.  
  17. // login with username and password
  18. $_login_result = ftp_login($_conn_id, $_user_name, $_user_pass);
  19.  
  20. // check connection
  21. if ((!$_conn_id) || (!$_login_result)) {
  22. $_error = "FTP connection has failed!";
  23. $_error .= "Attempted to connect to $_server for user $_user_name";
  24. $result = false;
  25. } else {
  26. $_error = "Connected to $_server, for user $_user_name";
  27. }
  28.  
  29. $conn_id = $_conn_id;
  30.  
  31. $file = "t.DOC";
  32. echo "Current directory: " . ftp_pwd($conn_id) . "\n";
  33. echo "<br/>";
  34.  
  35.  
  36. echo "<br/>";
  37. if (ftp_chdir($conn_id, "$remote_dir")) {
  38.  
  39. echo "Current directory is now After changes: " . ftp_pwd($conn_id) . "\n";
  40.  
  41. echo "<br/>";
  42. echo "<br/>";
  43. echo "<br/>";
  44.  
  45.  
  46. // try to delete $file
  47. if (ftp_delete($conn_id, $file)) {
  48. echo "$file deleted successful\n";
  49. } else {
  50. echo "could not delete $file\n";
  51. }
  52.  
  53.  
  54. }
  55. else {
  56. echo "Couldn't change directory\n";
  57. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: can not delete file from the FTP server,need help

 
0
  #2
Nov 24th, 2008
Check permissions for read/write/delete on the folder on the remote machine using the name / pass.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: can not delete file from the FTP server,need help

 
0
  #3
Nov 24th, 2008
i have complete permission on all ftp server and all folder over there.
still telling me permission demied
i change the delete code
  1. // try to delete $file
  2. if (ftp_delete($conn_id, $file)) {
  3. echo "$file deleted successful\n";
  4. } else {
  5. echo "could not delete $file\n";
  6. }

to
  1.  
  2. unlink($file);
but still i have problom
Last edited by peter_budo; Nov 24th, 2008 at 6:35 pm. Reason: Please use [code] instead of [quote]
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: can not delete file from the FTP server,need help

 
0
  #4
Nov 24th, 2008
Hmmm.. I have had problem with file creation using php, so I had to change folder permissions to 777 and just then it worked.

I think also that you do not change the ftp_delete command, as it is protocol dependent, not OS dependent. In my opinion directory permissions are the key
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: can not delete file from the FTP server,need help

 
0
  #5
Nov 24th, 2008
yes bro you are right ,that was the problom it is ok now.
i am now going to upolad my folder to ftp, but it give the follwoing errors
successfully created /wilbourn/ftptest
Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 54

Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 65

Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 66

Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 83



the is following
  1.  
  2. <?php
  3.  
  4. //Move or Upload Folder Using PHP FTP Functions
  5. function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
  6.  
  7. echo"$_user_name <br/>";
  8. echo"$_user_pass <br/>";
  9. echo" directories are : <br/>";
  10. echo"$local_dir<br/>";
  11. //echo"$remote_dir <br/>";
  12.  
  13.  
  14.  
  15. // set up basic connection
  16. $_conn_id = ftp_connect($_server);
  17.  
  18. // login with username and password
  19. $_login_result = ftp_login($_conn_id, $_user_name, $_user_pass);
  20.  
  21. // check connection
  22. if ((!$_conn_id) || (!$_login_result)) {
  23. $_error = "FTP connection has failed!";
  24. $_error .= "Attempted to connect to $_server for user $_user_name";
  25. $result = false;
  26. } else {
  27. $_error = "Connected to $_server, for user $_user_name";
  28. }
  29.  
  30. $conn_id = $_conn_id;
  31.  
  32. //$file = 'vaf3.pdf';
  33.  
  34. echo "Current directory: " . ftp_pwd($conn_id) . "\n";
  35. echo "<br/>";
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. echo "<br/>";
  43. if (ftp_chdir($conn_id, "$remote_dir")) {
  44.  
  45. echo "Current directory is now After changes: " . ftp_pwd($conn_id) . "\n";
  46.  
  47. echo "<br/>"; echo "<br/>"; echo "<br/>";
  48.  
  49. //unlink($file);
  50.  
  51. @ftp_mkdir($conn_id, $remote_dir);
  52. echo "successfully created $remote_dir\n";
  53.  
  54. $handle = opendir($local_dir);
  55. while (($file = readdir($handle)) !== false) {
  56. if (($file != '.') && ($file != '..')) {
  57. if (is_dir($local_dir . $file)) {
  58. //recursive call
  59. moveFolder($conn_id, $local_dir . $file . '/', $remote_dir . $file . '/');
  60. echo "successfully uploaded $file\n";
  61. } else
  62. $f[] = $file;
  63. }
  64.  
  65. }
  66. closedir($handle);
  67. if (count($f)) {
  68. sort($f);
  69. @ftp_chdir($conn_id, $remote_dir);
  70. foreach ($f as $files) {
  71. $from = @fopen("$local_dir$files", 'r+');
  72. $moveFolder = ftp_fput($conn_id, $files, $from, FTP_ASCII);
  73. // @ftp_fput($conn_id, $files, $from, FTP_BINARY);
  74. // check upload status
  75. if (!$moveFolder) {
  76. $this->_error = "FTP upload has failed! From:" . $local_dir . " To: " . $remote_dir;
  77. $result = false;
  78. } else {
  79. $this->_error = "Uploaded $local_dir to $remote_dir as $this->_server";
  80. $result = true;
  81. }
  82. }
  83. }
  84. return $result;
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. // get the file list for
  92. $buff = ftp_rawlist($conn_id, ".");
  93. echo "<br/>";
  94. var_dump($buff);
  95.  
  96. }
  97. else {
  98. echo "Couldn't change directory\n";
  99. }
  100.  
  101.  
  102. ftp_close($conn_id);
  103.  
  104. }
  105.  
  106. ?>
Last edited by peter_budo; Nov 24th, 2008 at 6:36 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: can not delete file from the FTP server,need help

 
0
  #6
Nov 25th, 2008
Well, honestly, I do not like while loops, so I would go with scandir() function in php that returns an array of all files. Then I will manipulate the array and upload file by file, rather than complete dir.
Also, I would like to use copy instead of move and once copy is successful, I would go with delete, calling another function.

But from the errors you get, I think the problem is here
  1. $from = @fopen("$local_dir$files", 'r+');
I think this should look like
  1. $from = @fopen("$local_dir/$files", 'r+');
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: can not delete file from the FTP server,need help

 
0
  #7
Nov 25th, 2008
ok i wil try on your idea then see what happened, i wil let you now later.
thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: can not delete file from the FTP server,need help

 
0
  #8
Nov 25th, 2008
now i havw following errors
successfully created wilbourn/ftptest/
Warning: ftp_fput() expects parameter 3 to be resource, boolean given in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 79

Fatal error: Using $this when not in object context in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 83
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: can not delete file from the FTP server,need help

 
0
  #9
Nov 25th, 2008
i have noe error,
but the programe not understand my local directory
c:/ exampledirectory
it gives me the following errors

Warning: opendir(C:\1) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 59

Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 60

i will show you the form i am using for data entry


<body>
<form method="post" action="upload.php" enctype="multipart/form-data" >

Move or Upload Folder Using PHP FTP Functions<br />
</p>
<table width="373" border="1">
<tr>
<td width="184">server address </td>
<td width="173"><input type="text" id="server_name" name="server_name" /></td>
</tr>
<tr>
<td>user name </td>
<td><input type="text" name="user_name" id="user_name" /></td>
</tr>
<tr>
<td>user password</td>
<td><input type="text" id="user_password" name="user_password" /></td>
</tr>
<tr>
<td>local directory</td>
<td><input type="text" name="local_dir" id="local_dir" /></td>
</tr>
<tr>
<td>remote directory</td>
<td><input type="text" name="remote_dir" id="remote_dir" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="upload" type="submit" id="upload" /></td>
</tr>
</table>
<p>&nbsp; </p>
</form>





</body>


do you think is there any syntax error or logical error.
waiting for reply
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC