SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP how do I move a file from one server to another?

    I have a php script that needs to move a file from one server to another server. They are both connected physically, and the firewall is configured to allow access. The local IP of the server I need to move the file to is 192.168.0.1

    I know I need to use the rename command, but I don't know what path to use to reference the second server.

    I know if this was a windows server I would map the folder where I want to move the file to, then in my page use the path to the folder, something like this //share-name/folder

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd suggest using FTP, or else map a path using NFS and then move the file just like you would between folders (because an NFS path is just like a folder path).

    PHP's FTP functions: http://us2.php.net/manual/en/ref.ftp.php
    Google for NFS if you need to know how to set that up.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I would rather not use FTP, because that would route it outside the firewall. I had them connect via an ethernet cable so I could make a direct transfer.

    Also I had other people tell me not to use NFS because I could access it directly, is this not true?

  4. #4
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using NFS is how you access it directly. Or similar setups, such as Samba (same kind of thing, but NFS is usually easier to set up).

    FTP won't inherently go outside the firewall. It's just like any other TCP connection in that it can easily go over your direct Ethernet cable connection. Just connect to the other computer via the IP address it has on that direct connection, and you're golden. If you're paranoid, tell the firewall to disallow outbound FTP connections and your FTP connection which won't go outside the firewall now can't.
    PHP questions? RTFM
    MySQL questions? RTFM

  5. #5
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is NFS something I have to install, or should it already be on the server? I found a tutorial for configuring it, but the command to start the service doesn't work. Do I have to install NFS?

  6. #6
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've only used Samba (because I've been on networks where the security issues of NFS were a problem, a situation that doesn't apply to you since you have only the two systems over a single direct cable), so I'm not sure if NFS needs to be installed or not; I was under the impression that it was part of every major *nix distro, but that seems not to be the case for you. Since you don't have the command, my instinct would be yes, you do have to install it.
    PHP questions? RTFM
    MySQL questions? RTFM

  7. #7
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help with this. I have NFS set up on both machines now, do I need to do anything special with permissions on the script or do I just give it the absolute path /mnt/foldername?

  8. #8
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Permissions need to be set the same way you would set them if you were moving between two directories on the same server. Essentially, using NFS you have made a particular subset of server B's filesystem a seamless part of server A's filesystem; in other words treat your NFS path just the same as you would any other directory on your server.
    PHP questions? RTFM
    MySQL questions? RTFM

  9. #9
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've mounted the folder in this websites public_html folder, but I get permission denied when trying to move files into it using PHP. I thought since it was moving it to a folder inside the website it would be ok, do you have any idea how I need to do this?

  10. #10
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All I can tell you is that the permissions on the folder need to be set to give your Apache user (or your PHP user if you're using su_exec or similar) write access to the directory. Try setting permissions to 777, and if that works start taking them away until it no longer works - the idea is that you want just enough permissions to let your script do what it needs to do and no more.
    PHP questions? RTFM
    MySQL questions? RTFM

  11. #11
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, that's what you meant. For some reason I was thinking something else when you were talking about permissions. I set the folder to 0777 and it worked perfectly.

    Thanks for all the help.

  12. #12
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, good, I was getting worried I had a complete lack of understanding of NFS! Although I suppose that wouldn't be too bad, being as I've never used it...
    PHP questions? RTFM
    MySQL questions? RTFM


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •