I’ve had my fair share of switching between operating systems in the past. Windows is the gaming platform for PC’s and Linux is the development platform that directly ties into my server in the data centre.
The reasons why I switched back to Windows were:
- My love for the PHP IDE, phpDesigner
- The lack of webcam support in Skype
- My code editor constantly crashing or hanging when trying to save a file on my server
And I tackled them all. I found a new love for Gedit, using a bunch of extensions. That rules out phpDesigner. Skype for Linux actually grew up to the minimum level of my requirements and now supports my mic and webcam. And as for the hanging of my code editor…
Why did the code editor hang in the first place?
It always happened when trying to save a file over ssh or ftp. My code editor hung on the fact it had to re-establish a lost ftp connection and then save the file, rather than being able to push it through an open connection. Since my Ctrl+S behavior is drilled to to the bone, I really had to wait a great number of times for my editor to respond yet again.
Is there a solution?
Yes there is and I use it on a daily basis. Never ever has the editor hung even once since that fix!
The solution is simple. The FTP directory is mounted to a local directory using GVFS. It’s the Gnome Virtual File System. Because Gnome has to support a number of legacy software, the mounted directories are accessible through a directory in the users home directory. ~/.gvfs/.
The directories are listed as follows:
~/.gvfs/$PROTOCOL as $USER on $DOMAIN, which translates to ~/.gvfs/ftp as johmanx on johmanx.com
Now, what is the minimal requirement for an ftp connection to stay open? It’s to run a command, how minimal it might be. Because we want to force it to send data, we use the minimal command that sends back a proper return value. ls. We know they’re all located in the ~/.gvfs directory, so we simple invoke the following:
#!/bin/bash while true do ls ~/.gvfs/ftp* &> /dev/null sleep 15 done
We need it to run bash commands, so the shebang points to /bin/bash. Because with invoking the command once, the connection won’t stay open forever, so we need to do that every once in a while. Connections tend to have a minimal timeout of 30 seconds, so to be save we repeat this “question” every half of that interval at 15 seconds.
The actual command is an ls to every directory inside the GVFS directory that starts with ftp, in the background, and the result will be dumped inside /dev/null, so it won’t clutter up any output screens.
To create a working version of this script, you can follow these steps:
- Create a file
keep-alive-ftpand put in there the script I just showed you. - Next, install it using
sudo install ./keep-alive-ftp /usr/binand make it executablesudo chmod +x /usr/bin/keep-alive-ftp - Whenever you want to edit an ftp file, run
keep-alive-ftp &so in the background, it will “pend” any open connections and then mount your ftp connection.
From this point on, you can edit your files like a breeze. All the lag that could show is any high latency between you and your server. To me that is of no concern, but it might to any of you out there.
Conclusion
I hope you liked my suggestion and if you’ve got any thoughts on how to make a more reliable or small impact solution to keeping your ftp connections alive, I’m open for it. Just leave a comment on the site.
Credit is due where it’s due. I did not come up with this solution. I found it somewhere on the vast internet. The implementation, however, is mine and I’m really happy with the results. I’m afraid I can’t retrace where I’ve found the initial idea.