How To Connect ftp Server Using php

Websolutionstuff | May-12-2021 | Categories : PHP

Hello All,

In this post i will show you how to connect ftp server using php.

PHP provide inbuilt function to connect ftp server using ftp_connect() function. Usnig ftp connection you can transferring files through FTP easily. Here i will show you how we can connect to ftp server and ftp login in php.

The ftp_connect() function opens an FTP connection to the specified host. When connection is open, you can run FTP functions against the server.

 

Syntax :

ftp_connect(host, port, timeout);

 

Parameter Details : 

host : This is Required parameter for ftp connection and Host Can be domain address or IP address.

 

port : This is Optional parameter for ftp connection, it specifies the port of the FTP server and default port  is 21.

 

timeout :  This is Optional parameter for ftp connection,it specifies timeout for all subsequent network operations and default timeout is 90 seconds.

 

Example :  

<?php

// connect to FTP server

$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");

// login to FTP server

$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

// close ftp connection

ftp_close($ftp_conn);
?>

 

Recommended Post
Featured Post
How To Integrate Stripe Payment Gateway In Laravel 9
How To Integrate Stripe Paymen...

In this article, we will see how to integrate the stripe payment gateway in laravel 9. stripe payment gateway is in...

Read More

Apr-10-2022

Bootstrap Modal In Angular 13
Bootstrap Modal In Angular 13

In this article, we will see the bootstrap modal in angular 13. Ng Bootstrap is developed from bootstrap and they p...

Read More

Jun-10-2022

How To Install Python On Ubuntu
How To Install Python On Ubunt...

In this article, we will see how to install python on ubuntu. Python is a popular programming language. P...

Read More

May-06-2022

How to Upload Image to Storage Folder in Laravel 10
How to Upload Image to Storage...

As I delve into Laravel 10, a true powerhouse in the realm of PHP frameworks, I've found it to be a game-changer for...

Read More

Sep-29-2023