Uploading a file automatically with FTP on the Raspberry Pi

I’ve been spending some time playing around with my Raspberry Pi (running Raspbian, an operating system based on Debian) and have set up some virtual servers to enable me to do some local web development. It makes for an easy way to develop as I can host the code in a central location which is easily accessible to all devices on my network. What isn’t so easy however is uploading any finished code to the web server – whilst this is straightforward from my desktop, it’s not so easy from my tablet.

In order to facilitate this I’ve written a bash script which I can easily run from a terminal window which will automatically upload a single file – this is because the website I’m currently working on has a single page, so I only need to upload one file. To do this I’m using the ncftp package which is not installed by default on Raspbian. To install it you need to use the following command from a Raspberry Pi terminal window:

sudo apt-get install ncftp

I then created a simple bash script which uses the ncftpput command to upload a single file. In the following script, change username, password, remote_server, remote_directory and local_file to the correct settings.

ncftpput -u username -p password remote_server remote_directory local_file

I saved my script to my home directory and called it upload.sh, which means in order to run it I simply use the following command:


If you find that this doesn’t work, you need to check that the script can be executed. To do this, use the following command:

sudo chmod +x upload.sh

It’s pretty easy really, but has the potential to be made more powerful if I find myself working on larger websites. ncftpput can upload entire directories and has many other useful features – check the NcFTP website for more details.

Posted in Development, Linux, Web | Leave a comment

Accessing the Instagram API with PHP

I’m planning on redesigning my website and part of this will involve retrieving my own Instagram posts to show the most recent ones on the homepage. It’s been a while since I did any coding and so I wanted to learn how to do it myself rather than using a plugin. The main recent change is that Instagram now requires an access token in order to use their API; thankfully, it is easy to acquire this using the Pixel Union website. Simply login using your Instagram credentials and a token will be generated.

I then used the following PHP function to access the Instagram API and retrieve my posts as JSON – I can then format these as necessary to display on the homepage. Just replace “INSERT_TOKEN_HERE” with the token generated at Pixel Union. There are various other endpoints available – just check the Instagram Developer website for full details.

function instagram_api_curl_connect( $api_url ){
   $connection_c = curl_init();
   curl_setopt( $connection_c, CURLOPT_URL, $api_url );
   curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 );
   curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
   $json_return = curl_exec( $connection_c );
   curl_close( $connection_c );
   return json_decode( $json_return, true );

$result = instagram_api_curl_connect("https://api.instagram.com/v1/users/self/media/recent/?access_token=INSERT_TOKEN_HERE");
Posted in Development, Instagram, PHP | Leave a comment

Widgets disappearing after updating to Marshmallow

My Moto G finally received the Marshmallow update last week, and I was especially glad to receive this due to the limited storage space available on the Moto G (only 8GB). Marshmallow allows you to include the SD card as part of the internal storage, meaning there is now much more space available and I no longer have to clear the cache every time I want to update an app!

I chose to wipe my phone’s memory and start again and the performance improvement was noticeable. However, whilst setting up my home screen I noticed that the BBC Weather widgets were unavailable. There didn’t seem to be any obvious reason for this – all other widgets were unaffected. After much investigation I found the culprit – the BBC Weather app had been installed to the SD card rather than to the internal memory. It seems that despite treating the combined storage as one big disk it isn’t quite that easy – apps installed on the SD card are unable to show widgets. The solution is easy – simply move the app to internal storage.

The steps to do this are:

  • Go to Settings, then Apps
  • Choose the app in question and press Storage
  • At the top under “Storage used” will be a Change button – press this and it will move the app

After doing this my BBC Weather widget was available again!

Posted in Android | Leave a comment

Outlook 2013 – Error 0x800CCC13 Cannot connect to the network after update to Windows 10

A client of mine recently reported a problem sending mail via Outlook 2013. The error in question was 0x800CCC13 – the Outlook test send and receive worked but no mail was being sent. We checked all of the SMTP settings, tried various ports and mail hosts but nothing was fixing it. My client then told me that he had recently updated to Windows 10 and the problems started around that time. It seems that the update was responsible, but thankfully there is an easy fix.

You need to have Administrator access and be able to run an elevated command prompt (you can do this by right clicking on it and running it as Administrator) – then, simply type in the following:

SFC /scannow

This solved the problem for my client – hopefully it will save someone else from having to do so much investigation!

Posted in Outlook, Windows | 1 Response

Windows 8.1 failing to update with error code 80244019

I recently noticed that my PC hadn’t updated Windows for 30 days, and trying to manually update it was failing with error code 80244019. I followed the troubleshooting steps on the Microsoft website but this made no difference. In the end I found a solution on reddit which worked immediately – all you have to do is open Control Panel, search for Windows Update, then choose the “Change settings” link on the left. Then you need to uncheck the box saying “Give me updates for other Microsoft products when I update Windows” as shown below:

Change update settings

Click OK and then try to update and hopefully this will now work! I assume this is related to the Windows 10 launch, I’ve had the prompt to update for about 30 days which is the same amount of time that it has not updated, I’ve been holding off until I have time to do it properly on my work PC.

Posted in Windows | Leave a comment

Changing the position of a Google+ badge in the WordPress sidebar

I recently added a Google+ badge to the sidebar of a WordPress website that I maintain. Adding the badge itself was straightforward, but I had some trouble because the minimum width of the badge was 180px and the width of my sidebar was 160px. This led to the badge being shifted to the right, like this:

Google+ badge before shifting to the left

The Facebook box and Twitter links above and below are centred correctly, but the Google+ box was over to the right ever so slightly. I tried changing the width, but eventually solved my problem very simply in CSS. I inspected the element and found that the badge is being displayed in an iframe inside a div called ‘___page0’. So I selected that div and the iframe inside it and shifted them both over to the left 10px, like so:

#___page_0, #___page_0 iframe{
position: relative;
left: -10px;

Now the badge is centred correctly!

Google+ badge after shifting to the left

I tried to change the width using CSS, but struggled as I think the width is set by the Javascript used to create the badge. I’m sure there must be some way of achieving this, but I’m happy with my CSS fix. Please let me know if you find a way of forcing the minimum width below 180px, it’d be really useful to know!

Posted in Development, Google+, Web, WordPress | 1 Response

Getting Drupal and WordPress to work on the same domain

This may be rather a niche problem, but I had a Drupal installation on keanei.me.uk where I wrote various tech-related articles. My plan was to learn about Drupal development whilst having this site set up, but I found that Drupal wasn’t really suited to my needs and that WordPress would be a better fit for the things that I want to do. So I wanted to archive the Drupal installation and get WordPress running on the same domain.

I installed WordPress in a subdomain on the site (I used /bike as I wanted to create a site about my cycling exploits). I wanted keanei.me.uk to automatically go to the /bike subdomain, but that would prevent access to the previous Drupal installation if I automatically redirected all traffic. It may have been possible to move the Drupal installation to a subfolder but then there would be numerous 404s from any links to it.

In the end, I added a few lines of code to the Drupal index.php script in the home directory of the domain. I added it at the top (but underneath the comments) so it is the first action undertaken.

if ($_SERVER[REQUEST_URI] == "/") {
	header("HTTP/1.1 301 Moved Permanently"); 
	header("Location: http://www.keanei.me.uk/bike"); 

What this code does is check to see if users are attempting to go directly to a previous URL from the Drupal installation – if so, then $_SERVER[REQUEST_URI] will not just be a / and so it will ignore the redirect. But if we are just attempting to go directly to the website, it will automatically redirect. So there is still full access to the Drupal installation, whilst the main keanei.me.uk will redirect to my new cycling website.

Posted in Development, Drupal, Web, WordPress | Leave a comment

View an Activity Playback directly from a Strava Activity

Strava is a very popular fitness activity tracking website, used by runners and cyclists to keep track of their exercise, as well as allowing users to compare their efforts with others in various ‘segments’ that are user-defined. I’ve been using Strava for a couple of years and have found it an excellent motivational tool.

Strava have recently launched Strava Labs, which features several projects that make use of Strava’s extensive dataset. One that I have found very interesting is the Activity Playback project, which allows you to view your activity on a map, stepping through time and seeing which other Strava users were on the road at the same time as you. This allows you to potentially identify people you’ve seen out and about – I used it recently to find someone who sucked my wheel for a while without so much as a ‘hello’.

All that is required to view this is your activity URL or ID – just copy the URL from the activity page and paste it on the Activity Playback page. However, I am lazy and so have developed a bookmarklet to do this for me. Now, when viewing a Strava activity, all I have to do is click the bookmarklet and it will take me directly to the Activity Playback page! Here is the code:

javascript:(function() {
	var activity = location.pathname.substr(12);
	if (activity % 1 == 0) {
		window.location = 'http://labs.strava.com/flyby/viewer/#' + activity;
	} else {
		alert('This should only be used on a Strava activity page.');

This is a simple piece of code, which takes the activity ID from the URL and then adds it to the Activity Playback base URL. To use it, you need to have a bookmarks bar visible in your browser. Then, drag this link: Strava Flyby – to the bookmarks bar, which will add the bookmarklet. Then, simply click it when viewing a Strava activity and voila!

There is very limited error checking – this is only designed to be used on a Strava activity page, if used elsewhere it will either display an error or just take you to the Activity Playback homepage. I’ve created a repository on GitHub for this – I’m sure it can be improved quite a lot but it suits my needs just fine for now.

Posted in Development, Strava | Leave a comment

Keeping track of my Twitter followers (now working with Twitter API v1.1)

The old script which I created to keep track of my Twitter followers stopped working when Twitter stopped access to their old API. The new API, v1.1, offers much more functionality but requires authentication in order to retrieve the list of followers. With this in mind, I updated the script in order to work with the new API.

To save time, I made use of the twitteroauth library created by Abraham Williams. It also utilises code from Web Dev Door – that page also has information about how to setup an application on Twitter, I would highly recommend following the details there.

The script works in a similar way to before, except this time I don’t need to poll Twitter for the username for each id – the initial request for the followers list provides all the information required.

I’ve updated the script on GitHub – if you need any help setting this up please give me a shout, I’d be happy to help.

Update 13/8/2014 – Twitter account ids can now be larger than the maximum value that can be stored in an INT, so I have changed the ‘id’ to a BIGINT rather than an INT in the SQL used to create the table. Thanks to Chris Millard for his help with this!

Posted in Development, Twitter | Leave a comment

Force web browsers to retrieve the latest version of a page from a WordPress site

I was having a bit of difficulty with a WordPress developed site recently. I had set up a members area which allowed users to retrieve messages and downloads, but users were finding that they would get a cached version of the page and would need to do a force refresh (e.g. Shift+F5 or Ctrl+Shift+R depending on your browser of choice) to get the latest version. I did not have a caching plugin installed on the site so was at a loss as to how to solve this issue.

In the end, I found a forum post on the WordPress Support site which helped me solve the issue. All that I had to do was edit the header.php file of my custom template, and add the following four lines right at the top of the file (just underneath the <?php tag):

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');

Now users will be able to see the latest messages and downloads without having to do a force refresh themselves. This is obviously at a cost of extra bandwidth, but it’s worth it so that the site acts as it should and users see up-to-date information.

Posted in Web, WordPress | Leave a comment