How to fix the error in pkg_add: Syntax error, command unrecognized

If you see following error:
Code:
sudo pkg_add -rv xxx
...
<<< 200 Switching to Binary mode.
binding data socket
>>> PORT 192,168,14,38,251,217
<<< 500 Illegal PORT command.
Error: Unable to get ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8-stable/Latest/xxx.tbz: [B]Syntax error, command unrecognized[/B]
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8-stable/Latest/xxx.tbz' by URL
pkg_add: 1 package addition(s) failed

> man pkg_add | less +/FTP_PASSIVE_MODE
Note: If you wish to use passive mode ftp in such transfers, set the
variable FTP_PASSIVE_MODE to some value in your environment. Otherwise,
the more standard ACTIVE mode may be used. If pkg_add consistently fails
to fetch a package from a site known to work, it may be because you have
a firewall that demands the usage of passive mode ftp.

SOLUTION
Just run the command by following FTP_PASSIVE_MODE=1:
Code:
> sudo [B]FTP_PASSIVE_MODE=1[/B] pkg_add -rv kcachegrind

Related thread:
http://forums.freebsd.org/showthread.php?t=3794
 
FTP_PASSIVE_MODE is defined by default in /etc/login.conf. However, sudo(8) by default clears environ()ment. So, you have to specify -E option or define !env_reset in Defaults in sudoers(5). OTOH, su(1) doesn't clear environment unless you specify -l option.

$ su root -c 'pkg_add -rv kcachegrind'
$ sudo -E pkg_add -rv kcachegrind
 
kenorb said:
Code:
>>> PORT 192,168,14,38,251,217
<<< 500 Illegal PORT command.
This is caused by a broken/non-existent NAT filter. The PORT command is not being rewritten when exiting your network, and the FreeBSD FTP server doesn't permit foreign port connections. (not that a foreign connection to an RFC1918 address would work anyway)
 
If you're going to enter lots of commands using sudo you might as well use a 'full' shell:
% sudo -s

Then set FTP_PASSIVE_MODE and start pkg_add'ing.
 
Back
Top