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.
Connecting to FTP Server:
$con = ftp_connect($host, 21);
Login to FTP Server:
ftp_login($con, $username, $password);
Uploading File:
ftp_put($con, $remote_file, $local_file, FTP_ASCII);
Closing Connection:
ftp_close($con);
Bring All Together:
$host = "localhost"; $username = "username"; $password = "password"; $local_file = 'path/to/file.txt'; $remote_file = 'public_html/file.txt'; $con = ftp_connect($host, 21) or die("Could not connect to FTP server"); $log = ftp_login($con, $username, $password) or die("Fail to longin"); $upload = ftp_put($con, $remote_file, $local_file, FTP_ASCII); if($upload) echo 'Success!'; ftp_close($con);
hi...
ReplyDeletei want to ask,how to upload multiple file via ftp using php?I take a lot of time in searching it....there is answer that we can use "multiple" but i don't know how to do the looping process..
Hope you can help me....
Thanks for your query! I hope this code will help you...
Delete$files = array(
'local/1.txt' => 'remote/1.txt',
'local/2.txt' => 'remote/3.txt',
'local/3.txt' => 'remote/3.txt');
foreach($files as $local => $remote){
$upload = ftp_put($con, $remote, $local, FTP_ASCII);
}
Thanks for your code...but,i don't know how to implement it in my coding.Can you help me by giving full example of codes that include html and php part...
Deleteonly PHP:
Deletehttp://pastebin.com/CC3xLG01
thanks...but i don't understand the array part which is:
Delete'path/to/local/file1.txt' => 'path/to/remote/file1.txt'
is it i have to write the path for the file to upload?
sorry,but can you give more clearer explanation on the codes that you give since i have took a lot of time on think about this.
DeleteOnly for you full and final! 100% working! tested ;)
Deletehttp://paste.laravel.com/192H
thanks for your code...but i still have problem where error like this "ftp_put() [function.ftp-put]: The parameter is incorrect."...What's wrong?
DeleteAnd also my ftp account is not localhost and have its username and password...i thought that we have to use the $ftp_server,$ftp_user_name,$ftp_user_pass??
Then,my upload directory is at Local Disk (C)...
What i've to change for this code??help me...
Sorry,for make you trouble...
please help me...
Deletedich vu ke toan thue dich vu lam bao cao tai chinh tín
ReplyDeletekhóa học kế toán thực hành re
cong ty dich vu ke toan
dich vu ke toan tai bac ninh
dịch vụ kế toán trọn gói giá rẻ
dịch vụ kế toán tại tp.hcm
dịch vụ báo cáo thuế
dịch vụ quyết toán thuế uy
học kế toán tại tphcm
học kế toán tại cầu giấy tín
học kế toán tại long biên
học kế toán tại hà đông re
học kế toán tại thanh xuân
học kế toán tại bắc ninh
học kế toán tại bình dương
học kế toán tại hải phòng
dịch vụ thành lập doanh nghiệp công ty trọn gói
dịch vụ thành lập doanh nghiệp công ty tại hải phòng
dịch vụ quyết toán thuế tại quận 5
dịch vụ quyết toán thuế tại quận 3
dịch vụ quyết toán thuế tại tphcm
dịch vụ quyết toán thuế tại quận cầu giấy
dịch vụ quyết toán thuế tại quận long biên
dịch vụ quyết toán thuế tại quận hà đông
dịch vụ quyết toán thuế tại quận thanh xuân
شراء اثاث مستعمل بجدة
ReplyDeleteشراء اثاث مستعمل جدة
شراء الاثاث المستعمل بجدة
شركة شراء اثاث مستعمل بجدة
شركة شراء الاثاث المستعمل بجدة
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeletePHP Training in chennai | PHP Training Course
PHP Training in chennai | Online PHP Course
Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.
ReplyDeletephp jobs in hyderabad.
• Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online course hyderabad
ReplyDelete