how to copy directories/files from a remote directory using php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamill
    New Member
    • Dec 2006
    • 71

    how to copy directories/files from a remote directory using php?

    I have two server one is window server as "A" and another is Linux server as "B".

    I have a directory on server "A" which contains several files and sub directories. I want to copy directories/files from server "A" to server "B" using php. I have control on both server but i want to run PHP script into Linux server "B".

    As i am not good in file handling so please help me to get rid from this problem.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    To copy the files from server A, the files need to be made available to server B somehow. FTP, SMB, HTTP, or something like that.

    Do you have the files shared in any way?
    If yes, the how so?
    If no, then you need to set something up.

    Comment

    • kamill
      New Member
      • Dec 2006
      • 71

      #3
      Dear Atli,

      Thanks for reply. Actually i want to use ftp related functions in below steps
      1- Open ftp of server "A"
      2-Open ftp of server "B"
      3-Copy the content of "A" into "B"

      I do not know this will work and if yes then how to implement this.

      Regards,
      Kamil

      Comment

      • jpr0325
        New Member
        • Mar 2010
        • 4

        #4
        There are FTP functions available in PHP, which you can use to connect and get content from server.

        Code:
        $con = ftp_connect("server.name"); 
        $login_result = ftp_login ($con, "username", "password"); 
        ftp_get($con,'targetpath', 'sourcepath', FTP_BINARY);
        Last edited by Dormilich; Mar 8 '10, 09:23 PM. Reason: Please use [code] tags when posting code

        Comment

        • kamill
          New Member
          • Dec 2006
          • 71

          #5
          Dear jpr0325

          Thanks for reply but this script can copy files/dir from remote server ("server.nam e") to the local machine and i want to copy from remote server and want to upload into another server where i will run this script.

          This will be helpful if you clear this script beacuse i have tried this but no luck.

          Regards,
          Kamil

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Then what you need to do is
            1. Open two FTP connections, one for each server
            2. ftp_get the file from server A into either a temporary "buffer" file or a memory buffer (a simple variable should do)
            3. ftp_put the file from your buffer to it's new location on server B.

            Use the examples provided above and in the manual (the links I posted above), and this should be no problem.

            Comment

            Working...