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



## kenorb (Nov 11, 2010)

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: [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
> ...



*SOLUTION*
Just run the command by following *FTP_PASSIVE_MODE=1*:

```
> sudo [B]FTP_PASSIVE_MODE=1[/B] pkg_add -rv kcachegrind
```

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


----------



## luna (Nov 11, 2010)

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`


----------



## aragon (Nov 11, 2010)

kenorb said:
			
		

> ```
> >>> 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 (Nov 12, 2010)

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.


----------

