469,282 Members | 2,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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

kamill
71
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.
Mar 8 '10 #1
5 5284
Atli
5,058 Expert 4TB
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.
Mar 8 '10 #2
kamill
71
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
Mar 8 '10 #3
There are FTP functions available in PHP, which you can use to connect and get content from server.

Expand|Select|Wrap|Line Numbers
  1. $con = ftp_connect("server.name"); 
  2. $login_result = ftp_login ($con, "username", "password"); 
  3. ftp_get($con,'targetpath', 'sourcepath', FTP_BINARY);
Mar 8 '10 #4
kamill
71
Dear jpr0325

Thanks for reply but this script can copy files/dir from remote server ("server.name") 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
Mar 9 '10 #5
Atli
5,058 Expert 4TB
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.
Mar 9 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Antonio Lopez Arredondo | last post: by
reply views Thread by Tess | last post: by
1 post views Thread by PRM | last post: by
reply views Thread by PRM | last post: by
6 posts views Thread by Wayne Wengert | last post: by
10 posts views Thread by yinglcs | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.