| | |
can not delete file from the FTP server,need help
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
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
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)
<?php //Move or Upload Folder Using PHP FTP Functions function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) { echo"$_user_name <br/>"; echo"$_user_pass <br/>"; echo" directories are : <br/>"; echo"$local_dir<br/>"; echo"$remote_dir <br/>"; // set up basic connection $_conn_id = ftp_connect($_server); // login with username and password $_login_result = ftp_login($_conn_id, $_user_name, $_user_pass); // check connection if ((!$_conn_id) || (!$_login_result)) { $_error = "FTP connection has failed!"; $_error .= "Attempted to connect to $_server for user $_user_name"; $result = false; } else { $_error = "Connected to $_server, for user $_user_name"; } $conn_id = $_conn_id; $file = "t.DOC"; echo "Current directory: " . ftp_pwd($conn_id) . "\n"; echo "<br/>"; echo "<br/>"; if (ftp_chdir($conn_id, "$remote_dir")) { echo "Current directory is now After changes: " . ftp_pwd($conn_id) . "\n"; echo "<br/>"; echo "<br/>"; echo "<br/>"; // try to delete $file if (ftp_delete($conn_id, $file)) { echo "$file deleted successful\n"; } else { echo "could not delete $file\n"; } } else { echo "Couldn't change directory\n"; }
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
i have complete permission on all ftp server and all folder over there.
still telling me permission demied
i change the delete code
to
but still i have problom
still telling me permission demied
i change the delete code
PHP Syntax (Toggle Plain Text)
// try to delete $file if (ftp_delete($conn_id, $file)) { echo "$file deleted successful\n"; } else { echo "could not delete $file\n"; }
to
PHP Syntax (Toggle Plain Text)
unlink($file);
Last edited by peter_budo; Nov 24th, 2008 at 6:35 pm. Reason: Please use [code] instead of [quote]
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
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
I miss my mind the most...."
Mark Twain
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
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
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)
<?php //Move or Upload Folder Using PHP FTP Functions function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) { echo"$_user_name <br/>"; echo"$_user_pass <br/>"; echo" directories are : <br/>"; echo"$local_dir<br/>"; //echo"$remote_dir <br/>"; // set up basic connection $_conn_id = ftp_connect($_server); // login with username and password $_login_result = ftp_login($_conn_id, $_user_name, $_user_pass); // check connection if ((!$_conn_id) || (!$_login_result)) { $_error = "FTP connection has failed!"; $_error .= "Attempted to connect to $_server for user $_user_name"; $result = false; } else { $_error = "Connected to $_server, for user $_user_name"; } $conn_id = $_conn_id; //$file = 'vaf3.pdf'; echo "Current directory: " . ftp_pwd($conn_id) . "\n"; echo "<br/>"; echo "<br/>"; if (ftp_chdir($conn_id, "$remote_dir")) { echo "Current directory is now After changes: " . ftp_pwd($conn_id) . "\n"; echo "<br/>"; echo "<br/>"; echo "<br/>"; //unlink($file); @ftp_mkdir($conn_id, $remote_dir); echo "successfully created $remote_dir\n"; $handle = opendir($local_dir); while (($file = readdir($handle)) !== false) { if (($file != '.') && ($file != '..')) { if (is_dir($local_dir . $file)) { //recursive call moveFolder($conn_id, $local_dir . $file . '/', $remote_dir . $file . '/'); echo "successfully uploaded $file\n"; } else $f[] = $file; } } closedir($handle); if (count($f)) { sort($f); @ftp_chdir($conn_id, $remote_dir); foreach ($f as $files) { $from = @fopen("$local_dir$files", 'r+'); $moveFolder = ftp_fput($conn_id, $files, $from, FTP_ASCII); // @ftp_fput($conn_id, $files, $from, FTP_BINARY); // check upload status if (!$moveFolder) { $this->_error = "FTP upload has failed! From:" . $local_dir . " To: " . $remote_dir; $result = false; } else { $this->_error = "Uploaded $local_dir to $remote_dir as $this->_server"; $result = true; } } } return $result; // get the file list for $buff = ftp_rawlist($conn_id, "."); echo "<br/>"; var_dump($buff); } else { echo "Couldn't change directory\n"; } ftp_close($conn_id); } ?>
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.
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
I think this should look like
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)
$from = @fopen("$local_dir$files", 'r+');
PHP Syntax (Toggle Plain Text)
$from = @fopen("$local_dir/$files", 'r+');
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
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> </td>
<td><input name="upload" type="submit" id="upload" /></td>
</tr>
</table>
<p> </p>
</form>
</body>
do you think is there any syntax error or logical error.
waiting for reply
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> </td>
<td><input name="upload" type="submit" id="upload" /></td>
</tr>
</table>
<p> </p>
</form>
</body>
do you think is there any syntax error or logical error.
waiting for reply
![]() |
Similar Threads
- Cannot find server or DNS Error - please help! (Viruses, Spyware and other Nasties)
- [DELPHI] ftp component error on PUT (Pascal and Delphi)
- Shell Script to Zip / FTP / Delete transactional files. (Shell Scripting)
- For Pay Shell Script - Zip / FTP / Delete transactional files (Shell Scripting)
- modify script (Perl)
- Explorer.exe Shell Hijack (HJT Log) (Viruses, Spyware and other Nasties)
- Quick Reference for Linux Commands (Getting Started and Choosing a Distro)
- ftplib and the retrbinary() command (Python)
- "Cannot find server or DNS Error" (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Simple question for PHP
- Next Thread: code not working
| Thread Tools | Search this Thread |
access ajax alexa apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display dropdown dynamic echo email encode error fairness file files folder form forms function functions google hack href htaccess html image include indentedsubcategory insert integration ip java javascript joomla limit link login mail mail() menu methods mlm multiple multipletables mysql newsletters oop passwords paypal pdf php problem provider query radio random recursion regex remote script search secure server sessions simple sms soap source space sql syntax system table tutorial update upload url user validator variable variables video voteup web xml youtube





