Tutorials · 4 min read

<a href="https://www.pexels.com/photo/black-laptop-computer-turned-on-showing-computer-codes-177598/">Photo by Markus Spiske from Pexels</a>

Helpful PHP Scripts Pt 2 - Upload Videos from an FTP Server

If you have video files on an FTP server and need a quick way to move them to api.video we have a helpful PHP script that will get the job done.

Erikka Innes

January 28, 2021

We're back with more helpful PHP scripts from Hervé Pita! If you have video content on an FTP server, you can use this script to move your files from there to api.video.

This script is part of a collection of scripts that help with bulk video uploads. Everything is available in our Helpful PHP Scripts repository on Github. In each part of this series, we'll walk through how to set up one of the scripts. What you'll find includes:

Today we're going to learn how to use the script for ingesting videos from an FTP server. Let's get started!

Prerequisites for Upload Videos from an FTP Server

For this project, you'll need to ensure that you have:

  • PHP 5.4 or greater with the command-line interface (CLI) and JSON extension installed
  • The Composer dependency management tool (or another way to manage your dependency management). See the Composer website for installation options.
  • A GitHub account
  • An Api.video account
  • Your API key for either production or sandbox
  • An FTP server account

You can also check out the API reference documentation for uploading a video here: Upload a video

Installation

  1. Navigate to the Helpful PHP Scripts repository.
  2. Click Code and from the drop-down click Download ZIP. (You can also install from the CLI if you prefer.)
  3. Put the contents of your new .zip file in a folder you want to work from.
  4. Navigate to the folder containing the contents of your zip file in the terminal.
  5. In the terminal, type: composer require api-video/php-sdk

Try the Script

  1. Type php import_from_ftp.php
  2. You're asked what environment you want to use, prod or sandbox. For our walkthrough, choose prod. NOTE: Make sure you have the correct API key, they are different for production and sandbox. Production is better because there is no watermark across your videos. In sandbox mode, all transferred videos will say 'FOR DEVELOPMENT PURPOSES ONLY' across them.
  3. You're asked to provide your API key, go ahead and paste in your Production API key. If you weren't sure where to get it from, navigate to your dashboard and grab the key from the Production section on the Overview page.
  4. If authentication is successful, you are next asked if you want to associate a playerID with your videos. You can customise and brand players, then associate them with videos if you like. (View a tutorial about video player customisation here.) For the sake of simplicity, we'll skip this. Type n.
  5. Now you're asked to provide the address for your FTP server. Type the complete address, exactly as it appears, or paste it in.
  6. Enter your FTP username.
  7. Enter your FTP password.
  8. Provide the path to the video folder on your FTP server that you want to use for the transfer.
  9. The script will now step through all your files and upload any videos it finds to api.video. You receive a note after each file is successfully written to api.video.

That's all for this installment of helpful PHP scripts! More to come!

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.

Affordable

Volume discounts and usage-based pricing to ensure you don’t exceed your budget.