# pkg_add -r Troubleshooting



## Prodiga1 (Jun 25, 2010)

Hello all--

I recently installed FreeBSD out of both need and a simple desire to understand Unix better.  One problem that I seem unable to solve is getting pkg_add -r to work for me.

I've read over and over again in the cloud that my problem is related to ftp passive mode-- which I have attempted to remedy both by doing:


```
$ftp
$ftp>passive
```

to toggle passive mode and:


```
set FTP_PASSIVE_MODE=true //or//
set FTP_PASSIVE_MODE="YES"
```

to no general success...

The following is the output of verbose pkg_add:


```
$ sudo pkg_add -vr apache
scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.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 xxxxxx
<<< 230 Login successful.
>>> PWD
<<< 257 "/"
>>> CWD pub/FreeBSD/ports/i386/packages-8.0-release/Latest
<<< 250 Directory successfully changed.
>>> MODE S
<<< 200 Mode set to S.
>>> TYPE I
<<< 200 Switching to Binary mode.
binding data socket
>>> PORT 128,101,135,195,228,234
<<< 200 PORT command successful. Consider using PASV.
initiating transfer
>>> RETR apache.tbz
<<< 425 Failed to establish connection.
Error: Unable to get [url]ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.tbz:[/url] Can't open data connection
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.tbz' by URL
pkg_add: 1 package addition(s) failed
```

I'd rather not have to port install every application I need...


----------



## SirDice (Jun 25, 2010)

Sudo strips variables from the environment. Sudo first, then set FTP_PASSIVE_MODE and then do a pkg_add -r.


----------



## Prodiga1 (Jun 25, 2010)

So something like:


```
$ su
Password:
x-128-101-135-195# set FTP_PASSIVE_MODE=true
x-128-101-135-195# pkg_add -vr apache
scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.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 xxxxxx
<<< 230 Login successful.
>>> PWD
<<< 257 "/"
>>> CWD pub/FreeBSD/ports/i386/packages-8.0-release/Latest
<<< 250 Directory successfully changed.
>>> MODE S
<<< 200 Mode set to S.
>>> TYPE I
<<< 200 Switching to Binary mode.
binding data socket
>>> PORT 128,101,135,195,208,104
<<< 200 PORT command successful. Consider using PASV.
initiating transfer
>>> RETR apache.tbz
<<< 425 Failed to establish connection.
Error: Unable to get [url]ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.tbz:[/url] Can't open data connection
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.tbz' by URL
pkg_add: 1 package addition(s) failed
```


----------



## SirDice (Jun 25, 2010)

What shell are you using?

If it's the standard csh you will have to use setenv:
[cmd=]setenv FTP_PASSIVE_MODE[/cmd]

NB you can use `% sudo -s` instead of su. Only members of the wheel group are allowed to use su.


----------



## Prodiga1 (Jun 25, 2010)

Let's see here:

My shell--


```
$ echo $SHELL
/bin/sh
```

Attempting sudo -s and setenv FTP_PASSIVE_MODE--


```
$ sudo -s
# setenv FTP_PASSIVE_MODE
setenv: not found
#
```


----------



## Prodiga1 (Jun 25, 2010)

Solved the problem, thanks for the help SirDice...

The correct command after sudo -s was:


```
export FTP_PASSIVE_MODE=true
```


----------



## DutchDaemon (Jun 25, 2010)

Prodiga1: format your posts correctly! http://forums.freebsd.org/showthread.php?t=8816


----------



## petko (Jun 27, 2010)

Hello,

I did follow the tutorial, but It seems that It did not worked for me.

here is the error:

```
pkg_add -rv sudo
scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/sudo.tbz]
---> ftp.freebsd.org:21
looking up ftp.freebsd.org
Error: Unable to get [url]ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/sudo.tbz:[/url] No address record
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/sudo.tbz' by URL
pkg_add: 1 package addition(s) failed
```
and I have internet connection on the server. Any ideas are much appreciated. Thanks in advance.


----------



## DutchDaemon (Jun 28, 2010)

> ```
> No address record
> ```



Your DNS resolving is out of order. Fix /etc/resolv.conf (resolver(5)).


----------



## petko (Jun 28, 2010)

Thank you for you replay.

Actually my resolv.conf seems to work because I able to connect to the outside.


```
> cat /etc/resolv.conf
search domain 
nameserver my ISP
nameserver my ISP
```

also this time the error message is different


```
<<< 425 Can't build data connection: Operation timed out.
Error: Unable to get [url]ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/sudo.tbz:[/url] Can't open data connection
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/sudo.tbz' by URL
pkg_add: 1 package addition(s) failed
```

I did check the pkg_add for the right path to the ftp. It use to work, but as soon as I apply nat rules with ipf it stop works. 
Thank you very much for you time. If I find a solution I will post it. Thanks again.


----------



## petko (Jun 28, 2010)

my nat is:


```
> cat /etc/ipnat.rules
map interface privateip/24 -> myip
```

Thanks


----------



## petko (Jul 6, 2010)

It's resolved, It was firewall issue. I had port 21 open but It didn't allowed to go out to the freebsd ftp,Thanks.


----------

