FTP "Aliases" on a Server by Mounting

If you are having a hard time trying to get your FTP program to find and use an alias to a directory on a server, you are trying to use the alias in the wrong way. What you are looking to do is mount a directory and bind it to another directory.  

The Problem

Say you have shell (SSH) access to a server. Logging in (scp username@server_address) you are taken to your personal user folder on that server (say "/home/johnvsc").   Now, you can traverse the directories with "cd" and you can also add an alias to your .bashrc or .profile  However, the problem is that those files are loaded into memory when you log in under SSH -> not when you log into FTP; therefore, those aliases are invisible to FTP.  

The Solution

Before you start, you probably want to make sure you have SUDO permissions (or do this logged in as "root"). If you don't, find an admin that can do this for you. If you don't know because it is your own box/slice; you get to figure it out ;)   To access a different directory from your user folder:

  1. Create a directory in your user directory that describes what the directory does:
    mkdir /home/johnvsc/link_to_www
  2. Mount an alias to that new directory:
    sudo mount --bind /srv/www/public_html /home/johnvsc/link_to_www
  3. Then when johnvsc logs in he can click the link_to_www directory and be taken to /srv/www/public_html

 

See, it is easy when you know how to do it.

I hope this saves you hours of frustration, like it has saved me!

Terms: BASH, FTP

Symlinks are a better way to

Symlinks are a better way to deal with this. Mounting requires root, and you will lose this on reboot of a machine unless you add the entry to /etc/fstab.

As your normal user, just do:ln -s /srv/www/public_html /home/johnvsc/link_to_www

That's it. It will persist across reboots, and doesn't require root. If your FTP server doesn't let you follow symlinks, then you just need to tweak a configuration setting.

Again, when I see the word

Again, when I see the word "just", I know there is going to be a problem.

So, to test your theory above, I navigated to my Linode Slice and, through the cl added the appropriate command. Then, I went to my FTP program (in this case, Transmit by Panic), logged into my Linode, clicked on the symlink and got this beautiful prompt: >

Now, personally, I don't think that it would be wise to replace a "Sites" folder anywhere with a link. To be honest, I never clicked on this to see what happens; not because I wouldn't be able to fix it if I hosed my site; but rather because I really don't want to waste the time to fix it.

So, the suggested solution above doesn't work me in the way that I need it to or in the environment that I need it to work in. And, judging my the quantity of posts I found on this subject, many people have found the same to be true.

I would strongly recommend

I would strongly recommend dumping ftp.

ftp passes your username and password in clear text.

Also, when you update settings files your database username and password are passed in clear text.

This is as bad a practice as using telnet instead of ssh.

I would remove the ftp program and inform people that they have to use sftp and that they can use a client like filezilla that supports sftp.

It is possible to secure ftp, just like it is possible to secure telnet. The reality is that you have not done so.

sftp is much less of a pain than securing ftp.

The ONLY legitimate current use for ftp is anonymous downloads. Otherwise remove it and use a program that is not exposing your server every time you use it.

You already have ssh working so you have no excuse for using ftp.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.