Difference between revisions of "Enable FTP Server"

From AwkwardTV
Jump to: navigation, search
(ATV Take 2 FTP)
 
(6 intermediate revisions by 2 users not shown)
Line 12: Line 12:
 
== FTPD Installation ==
 
== 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:
+
=== 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.
  
'''Give super-user privileges:'''
+
==== Get ftpd from an Intel Mac ====
<pre>sudo -s</pre>
+
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
  
'''Write the FTP configuration file:'''
+
Alternately, you can find an updated <code>ftpd</code> in MacOSXUpdCombo10.4.11Intel.dmg
<pre>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</pre>
 
  
 +
==== Get ftpd from the recovery partition ====
  
'''Reload that configuration file after changing it:'''
+
The recovery partition contains the file we are looking for.
<pre>launchctl load /System/Library/LaunchDaemons/ftp.plist</pre>
+
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
  
Simple as that. It should start working right away.
+
With this, you can proceed to enabling FTP as for an ATV Take 3.
  
=== ATV Take 2 FTP ===
+
=== ATV Take 3 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.
+
On the AppleTV Take 3, there is already an FTP server just waiting to be activated.
Alternately, you can find an updated ftpd in MacOSXUpdCombo10.4.11Intel.dmg
 
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):
+
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
  
'''A)'''<pre>sudo mount -uw /
+
Load the FTP daemon:
sudo touch /.readwrite
+
launchctl load $PLIST_FILE
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</pre>
 
  
 +
You should be ready to make an FTP access from your computer to the AppleTV.
  
For ATV 2.1 you must also add "frontrow allow" to the /etc/ftpusers file so that you can login with the frontrow user.
+
Below steps is not necessary for ATV take 3 (in my case, doing the below steps will prevent "frontrow" user to access FTP).   
 
 
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>
 
  
 +
Allow FTP access to user <code>frontrow</code>:
 +
USERS_FILE='/etc/ftpusers'
 +
cat >> $USERS_FILE <<CODE
 +
frontrow    allow
 +
CODE
  
'''B)''' Then perform the steps listed above for the 1.x installation
+
After this, your <code>/etc/ftpusers</code> 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 ===
 
=== Anonymous Write Access ===
Line 155: Line 149:
  
 
[[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.