Difference between revisions of "Enable FTP Server"

From AwkwardTV
Jump to: navigation, search
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
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:
+
== 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!!! 
  
'''Give super-user privileges:'''
+
Here's my setup as an example:
<pre>sudo -s</pre>
+
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 ==
 +
 
 +
=== ATV Take 2 FTP ===
 +
To enable FTP server in ATV Take 2 you will need to copy <code>ftpd</code> which is missing in Take 2.
 +
 
 +
==== Get ftpd from an Intel Mac ====
 +
From a Mac OS 10.4 (aka "Tiger"), copy:
 +
/usr/libexec/ftpd
 +
on the ATV to:
 +
  /usr/bin/ftpd
 +
 
 +
Log into your AppleTV and:
 +
sudo -s
 +
chmod +x /usr/bin/ftpd
 +
 
 +
Alternately, you can find an updated <code>ftpd</code> in MacOSXUpdCombo10.4.11Intel.dmg
 +
 
 +
==== Get ftpd from the recovery partition ====
 +
 
 +
The recovery partition contains the file we are looking for.
 +
At least mine, which started as a AppleTV 1.1 and has been upgraded to 3.0.2.
 +
 
 +
Get the file:
 +
sudo -s
 +
INSTALL_SOURCE='/tmp'
 +
DAEMON='usr/libexec/ftpd'
 +
 +
dd if=/dev/disk0s2 of=$INSTALL_SOURCE/recovery.dmg bs=1m
 +
hdiutil mount $INSTALL_SOURCE/recovery.dmg
 +
hdiutil mount /Volumes/Recovery/OS.dmg
 +
cp -p /Volumes/OSBoot\ 1/$DAEMON /usr/bin/
 +
chown root:wheel /$DAEMON
 +
hdiutil unmount /Volumes/OSBoot\ 1
 +
hdiutil unmount /Volumes/Recovery -force
 +
chown root:wheel /usr/libexec/ftpd
 +
 
 +
With this, you can proceed to enabling FTP as for an ATV Take 3.
 +
 
 +
=== ATV Take 3 FTP ===
 +
 
 +
On the AppleTV Take 3, there is already an FTP server just waiting to be activated.
 +
 
 +
Write the FTP launch daemon file:
 +
PLIST_FiLE='/System/Library/LaunchDaemons/ftp.plist'
 +
cat <<EOT > /$PLIST_FILE
 +
<?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/bin/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
 +
 
 +
Load the FTP daemon:
 +
launchctl load $PLIST_FILE
 +
 
 +
You should be ready to make an FTP access from your computer to the AppleTV.
 +
 
 +
Below steps is not necessary for ATV take 3 (in my case, doing the below steps will prevent "frontrow" user to access FTP). 
  
 +
Allow FTP access to user <code>frontrow</code>:
 +
USERS_FILE='/etc/ftpusers'
 +
cat >> $USERS_FILE <<CODE
 +
frontrow    allow
 +
CODE
  
'''Write the FTP configuration file:'''
+
After this, your <code>/etc/ftpusers</code> file should look like this:
<pre>cat <<EOT > /System/Library/LaunchDaemons/ftp.plist
+
# list of users disallowed any ftp access.
<?xml version="1.0" encoding="UTF-8"?>
+
# read by ftpd(8).
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+
Administrator
<plist version="1.0">
+
administrator
<dict>
+
root
        <key>Label</key>
+
uucp
        <string>com.apple.ftpd</string>
+
daemon
        <key>Program</key>
+
unknown
        <string>/usr/libexec/ftpd</string>
+
www
        <key>ProgramArguments</key>
+
frontrow    allow
        <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</pre>
 
  
 +
=== 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!'''
  
'''Reload that configuration file after changing it:'''
+
There are several steps here which may not be required - so this may need a little cleaning up.
<pre>launchctl load /System/Library/LaunchDaemons/ftp.plist</pre>
 
  
 +
'''Get into the correct state'''
 +
<pre>sudo -s</pre>
  
Simple as that. It should start working right away.
+
'''Create the directory where the anonymous user can dump files'''
 +
<pre>mkdir /mnt/FTP
 +
chmod a+w /mnt/FTP
 +
</pre>
  
=== ATV Take 2 FTP ===
+
'''Write the ftpd.conf file:'''
To enable FTP server in ATV Take 2 you will also need to copy the following file which is missing in Take 2: ftpd.
+
<pre>cat <<EOT > /etc/ftpd.conf
 +
umask all 022
 +
modify        guest
 +
chroot  GUEST  /mnt/FTP/
 +
EOT</pre>
  
Copy it from /usr/libexec/ftpd (tiger) to the same location on the ATV.
+
'''Allow the anonymous user to connect'''
Don't forget to chmod +x ftpd
+
<pre>echo 'anonymous allow' >> /etc/ftpusers
 +
echo 'ftp allow' >> /etc/ftpusers</pre>
  
'''If you have a 1.0 recovery partition do the following''' (Don't have a 1.1 image to test):
+
'''Create the FTP user'''
 +
<pre>niutil -create / /users/ftp
 +
niutil -createprop / /users/ftp uid 502
 +
niutil -createprop / /users/ftp gid 501</pre>
  
<pre>sudo mount -uw /
+
'''Restart the FTP server''' (this is the only way I know how short of restarting the system)
sudo touch /.readwrite
+
<pre>launchctl unload /System/Library/LaunchDaemons/ftp.plist
cd ~
+
launchctl load /System/Library/LaunchDaemons/ftp.plist</pre>
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</pre>
 
  
 +
Once this is done you can browse to your Apple TV, for example, from Windows Explorer by entering ''<nowiki>ftp://your.appletv.ip/</nowiki>''. 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.
  
 
[[Category:How-to]]
 
[[Category:How-to]]
 +
[[Category:ATV3]]
 +
[[Category:3.0.2]]

Latest revision as of 18:25, 17 July 2011

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

ATV Take 2 FTP

To enable FTP server in ATV Take 2 you will need to copy ftpd which is missing in Take 2.

Get ftpd from an Intel Mac

From a Mac OS 10.4 (aka "Tiger"), copy:

/usr/libexec/ftpd

on the ATV to:

 /usr/bin/ftpd

Log into your AppleTV and:

sudo -s
chmod +x /usr/bin/ftpd

Alternately, you can find an updated ftpd in MacOSXUpdCombo10.4.11Intel.dmg

Get ftpd from the recovery partition

The recovery partition contains the file we are looking for. At least mine, which started as a AppleTV 1.1 and has been upgraded to 3.0.2.

Get the file:

sudo -s
INSTALL_SOURCE='/tmp'
DAEMON='usr/libexec/ftpd'

dd if=/dev/disk0s2 of=$INSTALL_SOURCE/recovery.dmg bs=1m
hdiutil mount $INSTALL_SOURCE/recovery.dmg
hdiutil mount /Volumes/Recovery/OS.dmg
cp -p /Volumes/OSBoot\ 1/$DAEMON /usr/bin/
chown root:wheel /$DAEMON
hdiutil unmount /Volumes/OSBoot\ 1
hdiutil unmount /Volumes/Recovery -force
chown root:wheel /usr/libexec/ftpd

With this, you can proceed to enabling FTP as for an ATV Take 3.

ATV Take 3 FTP

On the AppleTV Take 3, there is already an FTP server just waiting to be activated.

Write the FTP launch daemon file:

PLIST_FiLE='/System/Library/LaunchDaemons/ftp.plist'
cat <<EOT > /$PLIST_FILE
<?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/bin/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

Load the FTP daemon:

launchctl load $PLIST_FILE

You should be ready to make an FTP access from your computer to the AppleTV.

Below steps is not necessary for ATV take 3 (in my case, doing the below steps will prevent "frontrow" user to access FTP).

Allow FTP access to user frontrow:

USERS_FILE='/etc/ftpusers'
cat >> $USERS_FILE <<CODE
frontrow    allow
CODE

After this, your /etc/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

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.