Code examples

PHP (ext-ftp)

This example needs the PHP FTP extension to be installed. It creates a CSV file in memory based on an array of stock data.
// Define shop upload key and inventory
$upload_key = '<<your upload key>>';
$inventory = [
'barcode' => '2001234567',
'price' => '1.99',
'quantity' => 24,
'currency' => 'USD'
// ...
// Connect to FTP server
$connection = ftp_connect('');
ftp_login($connection, 'apikey', $upload_key);
ftp_pasv($connection, true);
// Turn array into CSV
$handle = fopen('php://temp', 'r+');
ftruncate($handle, 0);
fputcsv($handle, array_keys($inventory[0]));
foreach ($inventory as $item) {
fputcsv($handle, array_values($item));
// Upload via FTP as stock.csv
ftp_fput($connection, 'stock.csv', $handle, FTP_BINARY, 0);
// Close file handle and connection

Javascript (Node.js)

This example uses the ftp-deploy package to upload the stock file to the FTP server. It expects a file named stock.csv to exist in the script's directory.
const FtpDeploy = require('ftp-deploy');
const ftpDeploy = new FtpDeploy();
const uploadKey = '<<your upload key>>';
const stockFileName = 'stock.csv';
const config = {
user: 'apikey',
password: uploadKey,
host: '',
port: 21,
localRoot: __dirname,
remoteRoot: '/',
include: [stockFileName],
deleteRemote: false,
forcePasv: true
ftpDeploy.deploy(config, function (err, files) {
if (err) {
console.log('Uploaded files', files);


A great low-tech way to get file uploads working in a PowerShell script that you execute on a timer.
# Update these variables
$csvPath = "C:\local\path\stock.csv" # Point this to your CSV file
$uploadKey = "xxxxxxxxx" # Set your Upload key / FTP password here
# Everything below here can stay the same
$request = [Net.WebRequest]::Create("")
$request.Credentials = New-Object System.Net.NetworkCredential("apikey", $uploadKey)
$request.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$fileStream = [System.IO.File]::OpenRead($csvPath)
$ftpStream = $request.GetRequestStream()
If you wish to verify your upload, you can get details like file size and upload date like this:
# This is optional - get file size and upload date to verify upload
$request = [Net.WebRequest]::Create("")
$request.Credentials = New-Object System.Net.NetworkCredential("apikey", $uploadKey)
$request.Method = [System.Net.WebRequestMethods+FTP]::GetDateTimeStamp
$response = $request.GetResponse()
$timestamp = $response.StatusDescription.Trim()
$request = [Net.WebRequest]::Create("")
$request.Credentials = New-Object System.Net.NetworkCredential("apikey", $uploadKey)
$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectoryDetails
$response = $request.GetResponse().GetResponseStream()
$StreamReader = New-Object System.IO.StreamReader $response
$filesize = 0
While ($file = $StreamReader.ReadLine()) {
If($file -like "*stock.csv*") {
$filesize = (($file -split "\D+") | Where-Object {$_})[3].Trim()
Write-Host "Upload date: $timestamp"
Write-Host "File size: $filesize"