[Solved]TFTP: Error code 2: Access violation

This post is an extension of my original post on TFTP: How to Setup TFTP. Although the post was written for Ubuntu, the same idea can be applied to all systems.

So, here is our problem. You set up a TFTP server. It starts fine. You upload a file, it gives no error. Now, you try to download a file, it throws you an error:

tftp> get myfile.jpg
Error code 2: Access violation

If you google the error message, Error code 2: Access violation on the web, you’ve probably noticed many solutions, some of them are very creative, such as running a touch command to create the file before downloading it etc. Before you try those solutions, ask yourself this question first: Do you want to touch 100 files before you download 100 files?

Anyway. I am not sure what cause the TFTP gives the error message: Error code 2: Access violation. However I never experienced this error in my system before with my configurations and settings. Therefore, I am going to share you my configurations for your reference.

My TFTP Configuration:

service tftp
{
   protocol = udp
   port = 69
   socket_type = dgram
   wait = yes
   user = nobody
   server = /usr/sbin/in.tftpd
   server_args = var/lib/tftpboot -s
   disable = no
}

There are couple things you need to pay attention. First, my TFTP root directory is /var/lib/tftpboot, and in my configuration file, I skip the first /. Second, I put a flag, -s in the server_args. That helps to keep TFTP from complain.


Next, the permission of the TFTP root directory plays an important role. Make sure that the permission and ownership are set correctly.

sudo chown -R nobody:nobody /var/lib/tftpboot
sudo chmo7 -R 777 /var/lib/tftpboot

Now, you can simply restart the system:

sudo service xinetd stop
sudo service xinetd start

and try to put a file and download it back:

tftp localhost
tftp> put myfile.jpg
Sent 56733279 bytes in 5.7 seconds

tftp> get myfile.jpg
Received 56733279 bytes in 5.7 seconds

That’s it.

Happy TFTP.

–Derrick

Our sponsors:

10 comments

  1. This was tried before, I had tried tftp-hpa too, I don’t know how many things I have tried. It is crazy if it not a bug.

    elder@elder-PC:~$ cat /etc/xinetd.d/tftp
    service tftp
    {
    protocol = udp
    port = 69
    socket_type = dgram
    wait = yes
    user = nobody
    server = /usr/sbin/in.tftpd
    server_args = var/lib/tftpboot -s
    disable = no
    }
    elder@elder-PC:~$ sudo apt-get install tftp tftpd
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    The following NEW packages will be installed:
    tftp tftpd
    0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0 B/33.0 kB of archives.
    After this operation, 168 kB of additional disk space will be used.
    Selecting previously deselected package tftp.
    (Reading database … 204295 files and directories currently installed.)
    Unpacking tftp (from …/tftp_0.17-18ubuntu2_amd64.deb) …
    Selecting previously deselected package tftpd.
    Unpacking tftpd (from …/tftpd_0.17-18ubuntu2_amd64.deb) …
    Processing triggers for man-db …
    Setting up tftp (0.17-18ubuntu2) …
    Setting up tftpd (0.17-18ubuntu2) …
    Note: xinetd currently is not fully supported by update-inetd.
    Please consult /usr/share/doc/xinetd/README.Debian and itox(8).
    elder@elder-PC:~$ sudo mkdir /var/lib/tftpboot
    elder@elder-PC:~$ sudo chown -R nobody:nobody /var/lib/tftpboot
    elder@elder-PC:~$ sudo chmod -R 777 /var/lib/tftpboot
    elder@elder-PC:~$ sudo service xinetd stop
    xinetd stop/waiting
    elder@elder-PC:~$ sudo service xinetd start
    xinetd start/running, process 24614
    elder@elder-PC:~$ tftp localhost
    tftp> put original
    Sent 6 bytes in 0.0 seconds
    tftp> get original
    Error code 2: Access violation
    tftp> quit
    elder@elder-PC:~$ rm original
    elder@elder-PC:~$ tftp localhost
    tftp> get original
    Error code 2: Access violation

    1. Please try debug what exactly happens using this command it may happens your default configuration change via other for the server_args = var/lib/tftpboot -s

      $tail /var/log/syslog

  2. The version of tftp I was using was using /svr/tftp as the baser directory for files even though I specified /tftpboot in the inetd.conf file.

    I changed everything to use /svr/tftp and it worked.

    Sounds like a potential program bug.

  3. In my case, I was trying to put a file to a remote server which already had a file by the same name. The remote tftpd was refusing to overwrite the file and giving back an access violation. Removing the remote file fixed the issue.

    Though I read the above while I was trying to figure it out, it wasn’t very helpful. Most of the suggestions seem like ‘voodoo fixes’ which usually sound something like “I changed this one option in a config file, rebooted, and then it worked. I can’t explain it, though.” Most of the time, if you can’t explain it, you probably just got lucky and worked around the problem without actually fixing it… or at least that’s been my experience.

  4. Thank you, that helped.

    My *nix days are long ago, had to do some firmware updates on a lot of HP Procurve switches, decided to set up tftp on a Freenas box and ran into the darned access violation issue.

    It’s kind of obvious that the files need to have the right access permissions, my mistake was that I wasn’t thinking (enough).

  5. Please try debug what exactly happens using this command it may happens your default configuration change via other for the server_args = var/lib/tftpboot -s

    $tail /var/log/syslog

Leave a Reply

Your email address will not be published. Required fields are marked *