It is easy to transfer/upload a file from one server to an other from php scripts. You have to use php ftp functions. If you have ftp access to other server(host, username, password), then you can follow following steps to upload a file from your loacl or from remote server to any other server.
1.First connect to the server where you want to send the file as:
$ftp=ftp_connect(“ftp.yourdomain.com”);
This will connect your php script to the other server.
2.Now open the file which you want to transfer or upload as:
$fp=fopen(‘myimage.jpg’, “r”);
You can open any file even any remote file using full file path.
3.Now login to ftp host using “username” and “password”.
ftp_login($ftp, “username”, “password”);
4.Now upload the file as:
ftp_fput($ftp, “public_html/myimage.jpg”, $fp, FTP_BINARY);
This function will put the file in public_html folder with same file name but you can use any name instead of “myimage.jpg”, the file will transfer with new name.
5.At end close ftp and opened file.
ftp_close($ftp);
fclose($fp);
Note: Here you need to specify the “public_html” folder name as most ftp give access to the main cPanel folder but if your ftp direct login in “public_html” then you don’t need to specify the “public_html” folder, just put file name. If you you are upolading file to any internal folder then you specify that folder name. Suppose you want upload the file to images folder then follow this:
ftp_fput($ftp, “public_html/images/myimage.jpg”, $fp, FTP_BINARY);
Full Code:
// Connect to ftp host
$ftp=ftp_connect(“ftp.yourdomain.com”);
// Open the file which is to be transfer
$fp=fopen(‘myimage.jpg’, “r”);
// Login to ftp host
ftp_login($ftp, “username”, “password”);
// Transfer the file in the “public_html” folder
ftp_fput($ftp, “public_html/myimage.jpg”, $fp, FTP_BINARY);
// Close ftp and opened file
ftp_close($ftp);
fclose($fp);
?>
Searched By:
inurl:/viewthread?thread= powered by vbulletin remote camera systems (3), term inurl:/guestbook html?page= (2), inurl:/guestbook php?new_message= amante (2), shared php server copy with http (1), send pwd ftp c sharp (1), script to move files from one directory to another within the ftp-server c# (1), saving files from one website to another website c# (1), save file to folder remote server c# (1), sample ftp file transfer script to another computer (1), remotely move a file from server to server (1), remotely copy files remote computer in c# (1), powered by vBulletin free ftp software (1), powered by vBulletin client server software (1), soap remote file uploade (1), “powered by vbulletin” contractor mortgages (1), transfer file to another computer using c# net (1), write the files from server using c# (1), vb6 store file remote server (1), vb6 file another computer login (1), vb6 copy to remote server (1)Related posts:
Heya, just wanted to thank you for the great post, I’m looking forward to your next one
Yes, right now I am working on a wp plugin and theme, so after completing that work I will add some more useful stuff.
Amazing. I want to read more. Will it be continued?
I feel you are too good to write Genius!Thanks for posting, maybe we can see more on this.
Hi,thanks for the great quality of your blog, each time i come here, i m amazed.
Thank you so much, it is great help, I have searched high and low for something like this..