Skip to content

Instantly share code, notes, and snippets.

@rochow
Created June 18, 2018 02:48
Show Gist options
  • Save rochow/92e76a03b29d0384679176ebf715ace1 to your computer and use it in GitHub Desktop.
Save rochow/92e76a03b29d0384679176ebf715ace1 to your computer and use it in GitHub Desktop.
Push a zip file to external server via FTP (handy for non-WP things, when on a dodgy connection etc)
<?php
$server = 'something.com';
$ftp_user_name = 'username';
$ftp_user_pass = 'password';
$filename = 'June2Site.zip';
$source = 'aaa/'.$filename;
$dest = '/new/'.$filename;
$mode = FTP_BINARY; // FTP_ASCII for text files (html, css, js etc)
$connection = ftp_ssl_connect ($server,24);
$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
if (!$connection || !$login) { die('Connection attempt failed!'); }
$upload = ftp_put($connection, $dest, $source, $mode);
if (!$upload) {
echo 'FTP upload failed!';
} else {
echo 'File uploaded!';
}
ftp_close($connection);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment