Skip to content

Instantly share code, notes, and snippets.

@thesjg
Forked from ryarwood/upload_file.php
Last active March 9, 2016 03:16
Show Gist options
  • Save thesjg/7550021 to your computer and use it in GitHub Desktop.
Save thesjg/7550021 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
function ftp_uploadfiles($conn_id, $local_dir)
{
$handle = opendir($local_dir);
while (($file = readdir($handle)) !== false)
{
if (($file != '.') && ($file != '..'))
{
$f[] = $file;
}
}
closedir($handle);
if (count($f) > 0)
{
sort($f);
foreach ($f as $files)
{
$from = fopen("$local_dir$files", 'r');
if (ftp_fput($conn_id, $files, $from, FTP_BINARY)) {
rename($local_dir.$files, "/home/114700/domains/vandaele.com/html/wp-content/themes/vandaele/xml_archive/".$files);
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
}
}
}
$ftp_server='209.112.18.232';
$ftp_server_port='21';
$ftp_user_name='XXX';
$ftp_user_pass='XXX';
$local_dir='/home/114700/domains/vandaele.com/html/wp-content/themes/vandaele/xml/';
//$conn_id = ftp_connect($ftp_server, $ftp_server_port);
//$conn_id = ftp_connect($ftp_server);
/* end error checking, remove for live file */
/* FTP IN */
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
ftp_login ($conn_id, $ftp_user_name, $ftp_user_pass);
/* RUN FUNCTION */
ftp_uploadfiles($conn_id, '/home/114700/domains/vandaele.com/html/wp-content/themes/vandaele/xml/');
/* GET OUT */
ftp_quit($conn_id);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment