≡ Menu

FTP Connection refused error – Solution to problem

If you get an error (ftp Connection refused) when using FTP client under Linux such as Connection refused, then you can fix this problem using following method.

Make sure ftp server installed

Make sure ftp server installed and service is running. Under Debian Linux you can use dpkg command to verify that ftp server installed:
$ dpkg -l | grep -i "ftp"Output:

ii  ftpd                           0.17-21                       FTP server

OR run following command:
$ dpkg -l | grep -i ftp
Under Red Hat/Novell Suse/Fedora Linux try rpm command:
# rpm -qa | grep -i "*ftp*"
In any case if you have the ftp package installed it will return output. If the ftp package is not installed, it will notify you or it will not give you any output at all. Naturally next logical step is to install FTP server.

Under Red Hat/Fedora Linux install vsftpd server as follows:
# up2date vsftpd
OR if you are using Fedora Linux use yum:
# yum install vsftpd
If you are using Debian Linux use apt-get command:
# apt-get install vsftpd
Next configure vsftpd by modifying /etc/vsftpd.conf file.

Is ftp server running (is port 21 open)?

Login to ftp server using ssh and try to telnet port 21 (to see port is open or not):
$ telnet localhost 21
Next run netstat -tulpn command to see if port 21 is in open:
$ netstat -tulpn | grep :21

Output:

tcp        0      0 0.0.0.0:21             0.0.0.0:*               LISTEN

OR try following command:
$ netstat -a | grep ftpOutput:

tcp        0      0 *:ftp                   *:*                     LISTEN

If port is not open, start ftp server /service. Under RedHat/Fedora Linux use service command:
# service vsftpd start
Under Debian Linux use following command:
# /etc/init.d/vsftpd start

FTP user permissions

Is particular user not allowed to use your vsftpd ftp server, then make sure user got permission to use your ftp server. File /etc/ftpusers - list of users disallowed use vsftpd server access. Make sure user name is not in this file.

Security or Firewall

Make sure iptables firewall/tcpd does not block access to your ftp server. Run following command on ftp server (login over ssh):
# iptables -L -nOutput:

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpts:6881:6882
ACCEPT     udp  --  202.54.1.254         0.0.0.0/0           udp dpt:514
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpts:80 state NEW,RELATED,ESTABLISHED
LOG        all  --  0.0.0.0/0            0.0.0.0/0           LOG flags 0 level 4
DROP       all  --  0.0.0.0/0            0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

Above output does not allows port 21 (port 21 is blocked by firewall). You need to use iptables rules to open port 21. Make sure file /etc/hosts.deny (TCPD wrappers) does not block access to port 21 for your ftp host.

{ 18 comments… add one }

  • Paul Greenwood November 28, 2006, 7:41 am

    Thanks the command service vsftpd start resolved temporarily my issue. I am now searching for where to add this so that this service starts at run level 3

  • nixCraft November 28, 2006, 8:53 am

    Paul,

    If you are using Redhat/CentOS/Fedora Core use ntsysv command to turn on vsftpd. If you are using other distro let me know name of distro.

    ntsysv

    • Anonymous June 15, 2010, 5:00 pm

      Awesome! Thanks for this command!

  • MAKKI AKASHA March 3, 2007, 9:34 am

    hi all iam working in encryptor project when iwant testing this project with ftp some problems was appeared like stalled

    PLEASE HELP ME

    THANKS FOR ALL

  • jjcrazy August 17, 2007, 5:06 pm

    Thanks you , The command ” service vsftpd start ”
    resolved my question . Have anywhere to study linux configure __come from china

  • mohamed yafiu August 23, 2007, 7:19 am

    hei…

    i can connect to the ftp port buy my user is not authorized to login? how can i fix this ?

  • Matthew September 25, 2007, 2:01 pm

    I tried everything here, my service is running, everything is working on the port 21. But when I try to log in with a user, this is the error I get:

    Transfer channel can’t be opened. Reason: A socket operation was attempted to an unreachable host.
    Error: Could not retrieve directory listing

    Anyone know why this is happening? I have made sure that iptables isn’t blocking my port and its still not working.

    • imran March 2, 2011, 10:36 am

      FTP Connection refused error – Solution to problem
      by Vivek Gite on April 13, 2006 · 11 comments

      If you get an error (ftp Connection refused) when using FTP client under Linux such as Connection refused, then you can fix this problem using following method.

      Make sure ftp server installed
      Make sure ftp server installed and service is running. Under Debian Linux you can use dpkg command to verify that ftp server installed:

      $ dpkg -l | grep -i “ftp”
      Output:

      ii ftpd 0.17-21 FTP serverOR run following command:

      $ dpkg -l | grep -i ftp

      Under Red Hat/Novell Suse/Fedora Linux try rpm command:

      # rpm -qa | grep -i “*ftp*”

      In any case if you have the ftp package installed it will return output. If the ftp package is not installed, it will notify you or it will not give you any output at all. Naturally next logical step is to install FTP server.

      Under Red Hat/Fedora Linux install vsftpd server as follows:

      # up2date vsftpd

      OR if you are using Fedora Linux use yum:

      # yum install vsftpd

      If you are using Debian Linux use apt-get command:

      # apt-get install vsftpd

      Next configure vsftpd by modifying /etc/vsftpd.conf file.

      Is ftp server running (is port 21 open)?
      Login to ftp server using ssh and try to telnet port 21 (to see port is open or not):

      $ telnet localhost 21

      Next run netstat -tulpn command to see if port 21 is in open:

      $ netstat -tulpn | grep :21

      Output:

      tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTENOR try following command:

      $ netstat -a | grep ftp
      Output:

      tcp 0 0 *:ftp *:* LISTENIf port is not open, start ftp server /service. Under RedHat/Fedora Linux use service command:

      # service vsftpd start

      Under Debian Linux use following command:

      # /etc/init.d/vsftpd start

      FTP user permissions
      Is particular user not allowed to use your vsftpd ftp server, then make sure user got permission to use your ftp server. File /etc/ftpusers – list of users disallowed use vsftpd server access. Make sure user name is not in this file.

      Security or Firewall
      Make sure iptables firewall/tcpd does not block access to your ftp server. Run following command on ftp server (login over ssh):

      # iptables -L -n
      Output:

      Chain INPUT (policy DROP)
      target prot opt source destination
      ACCEPT all — 0.0.0.0/0 0.0.0.0/0
      ACCEPT all — 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
      ACCEPT tcp — 0.0.0.0/0 0.0.0.0/0 tcp dpts:6881:6882
      ACCEPT udp — 202.54.1.254 0.0.0.0/0 udp dpt:514
      ACCEPT tcp — 0.0.0.0/0 0.0.0.0/0 tcp dpts:80 state NEW,RELATED,ESTABLISHED
      LOG all — 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4
      DROP all — 0.0.0.0/0 0.0.0.0/0

      Chain FORWARD (policy ACCEPT)
      target prot opt source destination

      Chain OUTPUT (policy ACCEPT)
      target prot opt source destination
      ACCEPT all — 0.0.0.0/0 0.0.0.0/0Above output does not allows port 21 (port 21 is blocked by firewall). You need to use iptables rules to open port 21. Make sure file /etc/hosts.deny (TCPD wrappers) does not block access to port 21 for your ftp host.

  • juno332 April 7, 2008, 12:01 am

    nice article i almost my ftp server using your help, but i had some firewall issues which i solved from another blog, Installing proftpd Thanks Guys you all brillaint .. my ftp server is working fine.

  • Bala October 9, 2009, 9:28 am

    I was not able to use ftp for long time on a linux machine. I finally tried to find the solution, got the solution here immediately.

  • C Moore October 21, 2009, 9:57 am

    Excellent, got the ftp working, would have been lost without knowing which service to look for and appropriate configuration file.

  • roger mathews January 16, 2010, 7:24 pm

    Thank you all, however I TURNED OFF YAHOO COOKIES AAND I can not turn them on, I am still looking sincerely Roger.

  • Reggie June 14, 2011, 4:23 pm

    Just to note that for permissions on vsftpd for RedHat based distros the ftpusers file and others are here /etc/vsftpd/ftpusers NOT simply under /etc/ftpusers

    Great article all the same because it helped me out! I was looking for /etc/ftpusers but once I found this article pointing to vsftpd it all came together.

  • praneeth July 18, 2011, 10:50 pm

    first try to ftp that server and see if you are able to connect..
    command: ftp server_name.

  • ahsan October 17, 2011, 8:05 pm

    i have a problem when i m logging to ftp wd username & passwd then this error is come

    [root@localhost ~]# ftp http://www.ahsan.com
    Connected to http://www.ahsan.com.
    220 (vsFTPd 2.0.5)
    530 Please login with USER and PASS.
    530 Please login with USER and PASS.
    KERBEROS_V4 rejected as an authentication type
    Name (www.ahsan.com:root): priya
    331 Please specify the password.
    Password:
    500 OOPS: cannot change directory:/home/priya
    Login failed.
    please give me the solution

  • Rajat February 10, 2012, 1:20 am

    Hmmm…great to find out, there were witohut a doubt a number of points that I hadn’t thought of before.

  • Bonduu October 31, 2012, 10:03 am

    I had same problem,gave me a lil headache trying to find a solution to it, I always got “connect: Connection refused” error.
    Then to resolve it, I checked my Redhat 5 server to see if ftp service is running,but alas it wasn’t just simply started it all everything became al-right.

    #service vsftpd start

    the cmd above was used to start my ftp service.

  • Victor Ferrero May 31, 2013, 2:47 pm

    so a couple days ago I spent all day trying to get ftp and ssh to work on a Linux server im setting up to use at a company. I followed every step by step guide perfectly but everytime I would try to connect I would get “connection refused error”. I came in to work today and the first time I tried to connect with ftp and ssh it worked perfectly. Turned out the problem was a conflicted ip address on the network. None of the forums I looked up suggested this and its a pretty easy fix so I would advise checking this if you are having ftp or ssh problems.

Leave a Comment