Thursday, 25 February 2016
Upload File with FTP using PHP
FTP is one of the most useful tool or protocol for all web developers or designers. We can move files from one server to another with FTP tools very easily. PHP provides build in support for FTP protocol. That’s why we can work with FTP very easily using some FTP functions. In this post I’m going to show how to upload or put file to a server using PHP functions.
<?php
$host = "localhost";
$username = "username";
$password = "password";
$local_file = 'path/to/file.txt';
$remote_file = 'public_html/file.txt';
#Connecting to FTP Server:
$con = ftp_connect($host, 21) or die("Could not connect to FTP server");
#Login to FTP Server:
$log = ftp_login($con, $username, $password) or die("Fail to longin");
#Uploading File:
$upload = ftp_put($con, $remote_file, $local_file, FTP_ASCII);
if($upload) echo 'Success!';
#Closing Connection:
ftp_close($con);
?>
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment