Monday 24 March 2014

Remotely modify a text file on your Raspberry Pi

My last blog post explained how to transfer files to and from your Raspberry Pi using FileZilla. It made use of SFTP (SSH File Transfer Protocol).

If I am programming and would like to remotely modify a Python file which is on my Raspberry Pi, I can do this through the command line. I would SSH into the Raspberry Pi and probably using nano (I do keep meaning to learn vim!) I can modify the file. It works really well.

However sometimes I find it a little clunky. I think it would be nice if I could use one of my favourite text editors on my computer to do this. As it happens SFTP is integrated into various other programs to make it easier to remotely modify a file already on your Raspberry Pi.

Now I know text editors, and which is the best one to use, has been debated to death for years. vi vs. emacs being the longest running battle probably ever. This battle even has its own wiki page http://en.wikipedia.org/wiki/Editor_war. It can be a very emotive subject for many people.

I happen to like Notepad++ on Windows and TextWrangler on the mac. Both these can remotely log into your Raspberry Pi to modify text files.

As with FileZilla in my previous blog post this is very easy to set up.

First TextWrangler.

Click on File and then Open from FTP/SFTP Server... in the drop down menu.



A new window should open, click on Connect...

This will open up yet another window as below.




Fill in the following details:
  • The IP Address of your Raspberry Pi. 
  • Check the SFTP Box.
  • Type in your Raspberry Pi User Name. 
  • Type in your Raspberry Pi Password. 
If you are unsure of your IP address of your Raspberry Pi this blog post will help you out. 

Your screen should look like this (but with your Raspberry Pi IP address.) 



You can now click on Connect.



You can now navigate through the file structure to the file you want to open. Once you have found it you can click on Open. 

The file will now be open in TextWrangler, and you can modify it as normal. 

It is a very similar process using Notepad++.

You should click on Plugins, and then on NppFTP, and check the Show NppFTP Window. This will open up a window on the right hand side of the text editor.




Now you should click on the Settings icon which is at the Right hand side of this additional window. It looks like a little cog wheel. When an option of General Settings or Profile Settings appears, you should select Profile Settings.



In this new window you should do the following.

  • Click Add New. 
  • When asked to enter a profile name type Raspberry Pi and click OK.
  • Type your Raspberry Pi's IP address.
  • Change connection type to SFTP.
  • Type in your Raspberry Pi Username.
  • Type in your Raspberry Pi Password.

Once you have completed your settings as below, with your own details, you can click Close.


Now to connect or disconnect to your Raspberry Pi click the little blue Dis(Connect) icon in the NppFTP window.



And then select the Raspberry Pi option from the drop down menu.

You will now be connected to your Raspberry Pi and can open any files you want to by selecting them from the folder structure in the window below.



If you prefer a different text editor to the ones I have mentioned above, why not see if it has the functionality to connect via FTP?

While I am make no claim that this is the best way to do this, or the only way, it is something I have found useful, and I am sure many of you will too!

2 comments:

  1. I am very grateful that I have crossed your site. Your content was very great that I cant stop reading each post that you have. I hope for the best outcome of your site. Thanks 온라인경마

    ReplyDelete
  2. People should know these tips because you have great content! Thanks anyway! 토토사이트

    ReplyDelete