Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 07-26-2008, 10:23 AM
  #1
thereal88
Soldier (Level 11)
 
thereal88's Avatar
 
Join Date: Apr 2006
Location: The Netherlands
Posts: 128
iTrader: (0)
thereal88 is an unknown quantity at this point
Question FTP File copying: how?

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_fileFTP_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?

Last edited by thereal88 : 07-26-2008 at 10:26 AM.
thereal88 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-26-2008, 10:16 PM
  #2
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 16,213
iTrader: (0)
Horus_Kol is a jewel in the roughHorus_Kol is a jewel in the roughHorus_Kol is a jewel in the roughHorus_Kol is a jewel in the rough
well - ftp connection needs to be made TO the destination server (anotherdomain.nl) not the local server
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-27-2008, 05:18 AM
  #3
¥åßßå
Blonde Bimbo
 
¥åßßå's Avatar
 
Join Date: Jul 2004
Posts: 1,610
iTrader: (0)
¥åßßå is a jewel in the rough¥åßßå is a jewel in the rough¥åßßå is a jewel in the rough
Based on your other post ( and this one ), try a simpler solution :

http://your-source-domain.com/getFile.php
PHP Code:
<?php
$key 
'put summat random here';
if( !empty( 
$_GET['key' ] ) && !empty( $_GET'file' ] ) && $_GET['key'] == $key )
{
    switch( 
$_GET['file'] )
    {
        case 
1:
            
$contents file_get_contents'functions.inc' );
            break;
            
        case 
2:
            
$contents file_get_contents'moveDir.inc' );
            break;

        case 
3:
            
$contents file_get_contents'installDB.inc' );
            break;
            
        case 
4:
            
$contents file_get_contents'connect_ct.inc.php' );
            break;
            
        default:
            
$contents '';
    }
    echo 
$contents;
}
?>
http://your-destination-domain.com/test.php
PHP Code:
<?php
$key 
'put summat random here'// this needs to be the same as the key in getFile.php ;)
$url 'http://your-source-domain.com/getFile.php?key='.$key.'&file=';
copy$url.'1''functions.inc' );
copy$url.'2''moveDir.inc' );
copy$url.'3''installDB.inc' );
copy$url.'4''connect_ct.php.inc' );
?>
¥
__________________
I may have opened the door, but you entered of your own free will
Blogrums
¥åßßå is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Reply
« Previous Thread | Next Thread »


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



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 04:36 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.