Skip to content

jlammx/php_upload_and_download_files_via_ftp_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP | Upload and download files via FTP server

This repository is an example of upload and download files via FTP server using PHP.

The primary purpose of an FTP server is to allow users to upload files.
Uploading and downloading files using PHP FTP functions is almost similar to doing it with an FTP client.

Functions

The ftp_connect(ftp_server) and ftp_login(ftp_connection, ftp_username, ftp_password) functions are used to establish the connection to the provided ftp host and log in with the ftp credentials.

$ftp_conn = ftp_connect($ftp_server);
$login = ftp_login($ftp_conn, $ftp_username, $ftp_password);

After successful logon, can use the ftp_put() or ftp_get() functions.

The ftp_put() fuction transfers the local file to the remote directory on FTP server. The function returns true or false based on the upload process and the success or error message will be displayed accordingly.

The ftp_get() fuction transfers the remote file on FTP server to the local directory. The function returns true or false based on the download process and the success or error message will be displayed accordingly.

ftp_put(ftp_conn, remote_file, local_file, mode, startpos);
// OR
ftp_get(ftp_conn, local_file, remote_file, mode, startpos);

Once the file transfer is completed, the ftp stream will be closed using the ftp_close() function.

ftp_close($ftp_conn);

Parameters

  • ftp_conn: ftp_conn is a required parameter and it is used to specify the FTP connection.
  • remote_file: remote_file is a required parameter and it is used to specify the file path to the upload path.
  • local_file: local_file is a required parameter and it is used to specify the path of the file to upload.
  • mode: mode is an optional parameter and it is used to specify the transfer mode. It has 2 possible values: 1) FTP_ASCII 2) FTP_BINARY.
  • startpos: startpos is an optional parameter and it is used to specify the position in the remote file to start uploading to.

Steps

  1. Create HTML form to upload file
  2. Define FTP settings
  3. Connect the FTP server
  4. Login the FTP server
  5. Upload or download file of FTP server
  6. Close the FTP server connection

Screenshots

🔴 Live

Skills

PHP MySQL


Jorge Aguirre     

Last updated at 20 Mar 2023

About

Upload and download files via FTP server using PHP.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published