PDA

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


kenorb
November 11th, 2010, 11:23
If you see following error:
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: Syntax error, command unrecognized
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:

> sudo FTP_PASSIVE_MODE=1 pkg_add -rv kcachegrind


Related thread:
http://forums.freebsd.org/showthread.php?t=3794

luna
November 11th, 2010, 12:43
FTP_PASSIVE_MODE is defined by default in /etc/login.conf. However, sudo by default clears environment. So, you have to specify -E option or define !env_reset in Defaults in sudoers. OTOH, su doesn't clear environment unless you specify -l option.

su root -c 'pkg_add -rv kcachegrind'
sudo -E pkg_add -rv kcachegrind

aragon
November 11th, 2010, 23:20
>>> 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)

SirDice
November 12th, 2010, 09:04
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.