943,752 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4099
  • PHP RSS
Nov 24th, 2008
0

can not delete file from the FTP server,need help

Expand Post »
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





PHP Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifkamalzahid is offline Offline
17 posts
since Nov 2008
Nov 24th, 2008
0

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

Check permissions for read/write/delete on the folder on the remote machine using the name / pass.
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Nov 24th, 2008
0

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

i have complete permission on all ftp server and all folder over there.
still telling me permission demied
i change the delete code
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  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]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifkamalzahid is offline Offline
17 posts
since Nov 2008
Nov 24th, 2008
0

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

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
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Nov 24th, 2008
0

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

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
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifkamalzahid is offline Offline
17 posts
since Nov 2008
Nov 25th, 2008
0

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

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
PHP Syntax (Toggle Plain Text)
  1. $from = @fopen("$local_dir$files", 'r+');
I think this should look like
PHP Syntax (Toggle Plain Text)
  1. $from = @fopen("$local_dir/$files", 'r+');
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Nov 25th, 2008
0

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

ok i wil try on your idea then see what happened, i wil let you now later.
thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifkamalzahid is offline Offline
17 posts
since Nov 2008
Nov 25th, 2008
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifkamalzahid is offline Offline
17 posts
since Nov 2008
Nov 25th, 2008
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifkamalzahid is offline Offline
17 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Simple question for PHP
Next Thread in PHP Forum Timeline: code not working





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC