api.video

Features

Documentation

Tutorials

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

January 28, 2021 - Erikka Innes

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

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 my.api.video 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!

Erikka Innes

Developer Evangelist

Get started now

Connect your users with videos