Difference between revisions of "Enable FTP Server"

From AwkwardTV
Jump to: navigation, search
m (Updated the installation instructions for ATV 2.1)
Line 1: Line 1:
 +
== Why Standard FTP? ==
 +
Why would you want to turn on  a standard, non-secure FTP server on your ATV??  Well the answer for me was simple . . . SPEED!!! 
 +
 +
Here's my setup as an example:
 +
iMac -> wireless 802.11n -> Airport Extreme -> Ethernet cable -> ATV
 +
 +
SFTP - Avg xfer speed = 2Mb/s<br>
 +
FTP  - Avg xfer speed =  '''7Mb/s'''!!!!!
 +
 +
That alone was a good enough reason for me!  If you're worried about security then you should stick with the SFTP server which is usually installed when using the Patchstick. 
 +
 +
== FTPD Installation ==
 +
 
There is already an FTP server on the AppleTV just waiting to be activated. It's relatively simple to do so. Cut and paste the seperate code blocks into a terminal window:
 
There is already an FTP server on the AppleTV just waiting to be activated. It's relatively simple to do so. Cut and paste the seperate code blocks into a terminal window:
  
Line 63: Line 76:
 
sudo chmod +x /usr/libexec/ftpd
 
sudo chmod +x /usr/libexec/ftpd
 
sudo chown root:wheel /usr/libexec/ftpd</pre>
 
sudo chown root:wheel /usr/libexec/ftpd</pre>
 +
 +
 +
For ATV 2.1 you must also add "frontrow allow" to the /etc/ftpusers file so that you can login with the frontrow user.
 +
 +
From your local machine, copy the /etc/ftpusers file to your local machine
 +
<pre>
 +
scp -1 frontrow@appletv.local:/etc/ftpusers $HOME/Desktop
 +
</pre>
 +
 +
The file will be copied to your Desktop.  Open it with TextEdit (or your favorite ASCII editor, since I'm a geek I prefer 'vi'), and add the "frontrow allow" line to the end of the file.
 +
 +
After the edit your ftpusers file should look like this:
 +
 +
<pre>
 +
# list of users disallowed any ftp access.
 +
# read by ftpd(8).
 +
Administrator
 +
administrator
 +
root
 +
uucp
 +
daemon
 +
unknown
 +
www
 +
frontrow allow</pre>
 +
 +
Ensure that you DO NOT add the ".txt" extention to the file, it should only be called "ftpusers".
 +
 +
All that remains is to copy it back to your ATV, ssh to your ATV, change the ownership and copy it back to the correct location.
 +
 +
From your local machine:
 +
<pre>
 +
scp -1 $HOME/Desktop/ftpusers frontrow@appletv.local:~
 +
ssh -1 frontrow@appletv.local
 +
<enter 'frontrow' as the password when prompted>
 +
sudo chown root:wheel ftpusers
 +
sudo mv ftpusers /etc/ftpusers
 +
</pre>
 +
  
 
'''B)''' Then perform the steps listed above for the 1.x installation
 
'''B)''' Then perform the steps listed above for the 1.x installation

Revision as of 06:09, 31 July 2008

Why Standard FTP?

Why would you want to turn on a standard, non-secure FTP server on your ATV?? Well the answer for me was simple . . . SPEED!!!

Here's my setup as an example: iMac -> wireless 802.11n -> Airport Extreme -> Ethernet cable -> ATV

SFTP - Avg xfer speed = 2Mb/s
FTP - Avg xfer speed = 7Mb/s!!!!!

That alone was a good enough reason for me! If you're worried about security then you should stick with the SFTP server which is usually installed when using the Patchstick.

FTPD Installation

There is already an FTP server on the AppleTV just waiting to be activated. It's relatively simple to do so. Cut and paste the seperate code blocks into a terminal window:

Give super-user privileges:

sudo -s


Write the FTP configuration file:

cat <<EOT > /System/Library/LaunchDaemons/ftp.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.apple.ftpd</string>
        <key>Program</key>
        <string>/usr/libexec/ftpd</string>
        <key>ProgramArguments</key>
        <array>
                <string>ftpd</string>
                <string>-l</string>
        </array>
        <key>Sockets</key>
        <dict>
                <key>Listeners</key>
                <dict>
                        <key>Bonjour</key>
                        <true/>
                        <key>SockServiceName</key>
                        <string>ftp</string>
                </dict>
        </dict>
        <key>inetdCompatibility</key>
        <dict>
                <key>Wait</key>
                <false/>
        </dict>
</dict>
</plist>
EOT


Reload that configuration file after changing it:

launchctl load /System/Library/LaunchDaemons/ftp.plist


Simple as that. It should start working right away.

ATV Take 2 FTP

To enable FTP server in ATV Take 2 you will also need to copy the following file which is missing in Take 2: ftpd.

Copy it from /usr/libexec/ftpd (tiger) to the same location on the ATV. Don't forget to chmod +x ftpd

If you have a 1.0 recovery partition do the following (Don't have a 1.1 image to test):

A)
sudo mount -uw /
sudo touch /.readwrite
cd ~
sudo dd if=/dev/disk0s2 of=recovery.dmg bs=1m
hdiutil mount recovery.dmg
hdiutil mount /Volumes/Recovery/OS.dmg
sudo cp -p /Volumes/OSBoot\ 1/usr/libexec/ftpd /usr/libexec/ftpd
sudo chmod +x /usr/libexec/ftpd
sudo chown root:wheel /usr/libexec/ftpd


For ATV 2.1 you must also add "frontrow allow" to the /etc/ftpusers file so that you can login with the frontrow user.

From your local machine, copy the /etc/ftpusers file to your local machine

scp -1 frontrow@appletv.local:/etc/ftpusers $HOME/Desktop

The file will be copied to your Desktop. Open it with TextEdit (or your favorite ASCII editor, since I'm a geek I prefer 'vi'), and add the "frontrow allow" line to the end of the file.

After the edit your ftpusers file should look like this:

# list of users disallowed any ftp access.
# read by ftpd(8).
Administrator
administrator
root
uucp
daemon
unknown
www
frontrow	allow

Ensure that you DO NOT add the ".txt" extention to the file, it should only be called "ftpusers".

All that remains is to copy it back to your ATV, ssh to your ATV, change the ownership and copy it back to the correct location.

From your local machine:

scp -1 $HOME/Desktop/ftpusers frontrow@appletv.local:~
ssh -1 frontrow@appletv.local
 <enter 'frontrow' as the password when prompted>
sudo chown root:wheel ftpusers
sudo mv ftpusers /etc/ftpusers


B) Then perform the steps listed above for the 1.x installation

Anonymous Write Access

To allow anonymous access (with write support) several steps need to be taken. Don't do this if your Apple TV is directly connected to the internet for what ever reason!

There are several steps here which may not be required - so this may need a little cleaning up.

Get into the correct state

sudo -s

Create the directory where the anonymous user can dump files

mkdir /mnt/FTP
chmod a+w /mnt/FTP

Write the ftpd.conf file:

cat <<EOT > /etc/ftpd.conf
umask all 022
modify        guest
chroot  GUEST   /mnt/FTP/
EOT

Allow the anonymous user to connect

echo 'anonymous allow' >> /etc/ftpusers
echo 'ftp allow' >> /etc/ftpusers

Create the FTP user

niutil -create / /users/ftp
niutil -createprop / /users/ftp uid 502
niutil -createprop / /users/ftp gid 501

Restart the FTP server (this is the only way I know how short of restarting the system)

launchctl unload /System/Library/LaunchDaemons/ftp.plist
launchctl load /System/Library/LaunchDaemons/ftp.plist

Once this is done you can browse to your Apple TV, for example, from Windows Explorer by entering ftp://your.appletv.ip/. You will be taken directly to the /mnt/FTP/ directory, allowing you to drag and drop files across directly. I found this faster (no encryption) and easier than using SCP, plus most OS's have an integrated FTP client these days.