FTP connection refused issue

Hi All,

I am using the below script to get some files from the remote location

 
HOST='Test03'
USER='root'
PASSWD='*****'
FILE='/home/user/d.txt'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
get $FILE
quit
END_SCRIPT
exit 0

But ist is giving me the error "Connection refused"

I am giving the right username , password and hostname. I dont have to apply the ssh-keys as i want to do it by giving password.

Is FTP daemon running on your server ? Have you managed to connect and transfer the file manually ?

Please find the following ftp script to download file from server.

=================================

HOST='Test03'
USER='user'
PASSWD='*****'
FILE='d.txt'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
bin        
get $FILE
quit
END_SCRIPT
exit 0

=================================

First make sure you are able to download the file manually.

Also check if 'root' is allowed access to FTP.

Change the FILE variable from

FILE="/home/user/d.txt"

to

FILE='d.txt'

Note : If you don't use bin, you may get following warning.

WARNING! 1 bare linefeeds received in ASCII mode
File may not have transferred correctly.

1 Like

You don't say which Unix/Linux flavor this is but, talking generic Unix, since you are wanting to use ordinary ftp (along with the security issues that might give you) you can use a .netrc file to hold the remote login credentials. Google for .netrc

.netrc must reside in the home directory under which the command will run and have read access only for that user.

Once this is configured properly to can test it interactivley by typing the command:

 
ftp Test03

(using the node name in your script) and the ftp session should connect immediately if all is well. You can then write your script without userid/passwd concerns.

Hope that helps.

1 Like