Tuesday, May 31, 2011

FreeBSD pkg_add error: Syntax error, Command not found.

Today I had a problem while installing "cvsup" package in my FreeBSD development system. pkg_add was constantly failing to fetch files from the remote repository. Here is the error message that I was getting.

#pkg_add -r cvsup
Error: Unable to get ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz: Syntax error, command unrecognized
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz' by URL

Tried setting the passive mode ftp with 

setenv FTP_PASSIVE_MODE 1

and re-ran the pkg_add command but with out any luck. Then I tried 

#pkg_add -rv cvsup

Which gave me the following verbrose output.

Error: Unable to get ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz: Syntax error, command unrecognized
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz' by URL
freebsd# pkg_add -rv cvsup
scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz]
---> ftp.freebsd.org:21
looking up ftp.freebsd.org
connecting to ftp.freebsd.org:21
<<< 220 Welcome to freebsd.isc.org.
>>> USER anonymous
<<< 331 Please specify the password.
>>> PASS [email protected]
<<< 500 OOPS: cannot change directory:/home/ftp
Error: Unable to get ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz: Syntax error, command unrecognized
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.2-release/Latest/cvsup.tbz' by URL
pkg_add: 1 package addition(s) failed

With the above detailed error report, it seems that the ftp server at ftp.freebsd.org is not configured well or is broken. So I checked the DNS record of ftp.freebsd.org with;

#dig ftp.freebsd.org
ftp.freebsd.org.        180     IN      A       204.152.184.73
ftp.freebsd.org.        180     IN      A       87.51.34.132
ftp.freebsd.org.        180     IN      A       149.20.64.73

It turned out that there were three hosts associated with ftp.freebsd.org. I randomly picked up one hoping that it will not be same as the one that pkg_add is currently connecting to and set and environment variable

# setenv PACKAGEROOT ftp://149.20.64.73/

and re-ran the command

# pkg_add -r cvsup

and it started installing the packages, including the dependencies.