Code examples

PHP (ext-ftp)

This example needs the PHP FTP extension (opens in a new tab) 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 (opens in a new tab) 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 (opens in a new tab).

# 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()