Hi, I have some questions about FTP file copying in PHP, because I can't figure it out by searching the Net.
What I want to do is use a file:
http://www. mydomain .nl/ test.php
to copy a file
http://www. anotherdomain .nl/ copyfile.php
to
http://www. mydomain .nl/ copyfile.php
I'm testing with two domains on one server, but I eventually I want to be able to copy from one server to another.
Using this function:
PHP Code:
function ftp_copy($source_file, $destination_file)
{
$ftp_server = 'ftp.mydomain.nl';
$ftp_user = 'user';
$ftp_password = 'password';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_password);
if((!$conn_id) || (!$login_result))
{
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user";
}
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
ftp_close($conn_id);
if(!$upload)
{
echo "FTP copy has failed!";
return false;
}
else
{
return true;
}
}
// define some variables
$destination_file = 'copyfile.php';
$server_file = 'copyfile.php';
if(ftp_copy ($server_file, $destination_file))
{
echo("Operation succeeded and stuff");
}
What this does, is copying the file /domains/mydomain.nl/public_html/copyfile.php
to /copyfile.php (in the root).
So there are two things wrong with this:
- The file is copied
from the location it should be copied
to;
- The file is copied to the root of the server.
However, if I try adding the path /domains/mydomain.nl/public_html/ to the destination, it says 'Permission denied', while all CHMOD permissions are checked in the destination folder.
Can anyone tell me how it should be?