FTP Login Error check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP Login Error check
# 15  
Old 02-24-2012
Quote:
Originally Posted by methyl
Just for completeness, how are you giving the ftp process the login name and password? Is it from the keyboard of from a .netrc file or from "expect"? There is no "user" line in your ftp script so it can't be that way.

For a tight script you'll need to also check the exit status (a poster earlier showed how) and check for more different error messages. Once you have one robust script it becomes easy to either clone it or turn it into a utility.

I use the .netrc to login. The other if condition someone suggested did not do anything at all. It never detected the errors at all. it alwars returns a 0 so that if is useless. My design works just fine for the login id check if it failed or not. That is all I wanted to do at this point. I also have another ping check which I did not list here to check if the server is even reach-able. The login failed check works. Again I was hoping to have a one command check, but no easy way in the ftp scripting !

---------- Post updated at 04:33 PM ---------- Previous update was at 04:32 PM ----------

Thank you all for participating in this log.
# 16  
Old 02-24-2012
If the FTP client doesn't return proper error codes, looking at the logfile is about all you can do.
# 17  
Old 02-24-2012
Tip about "ping". Send a couple of packets and totally ignore the result. Then send your real "ping" test.

The ftp protocol is crude from 20+ years ago but is still in use because it is simple and is the only TCP/IP File Transfer Protocol which works across disparate platforms regardless of their age.

In system design ftp is the last resort when all modern secure protocols are not available. In practice ftp is in widespread use because it is simple and easy to use.

My "reliable" ftp scripts rarely exceed 600 lines.


@mrn6430
Quote:
The other if condition someone suggested did not do anything at all. It never detected the errors at all. it alwars returns a 0
The return code from ftp is indeed zero when the password ifs wrong. It is non-zero when the file transfer failed. Still worth checking the return code from ftp.
Code:
# Somethng like
ftp  ;  REPLY=$?


Last edited by methyl; 02-24-2012 at 09:00 PM.. Reason: typos
# 18  
Old 02-24-2012
Hi, consider this ftp code:
Code:
ftp -n  << EOF > $LOG_FILE
   verbose
   open ${SERVER} 
   $LOGON
   binary
   cd ${REMOTE_FILE_PATH}
   put ${LOCAL_FILE_NAME}
   close
   bye
EOF

FILE_TRANSFER_COUNT=`cat ${LOG_FILE} | grep -v 'bytes' | grep -c ^'226 '`
IS_FTP_FAILED=`cat ${LOG_FILE} | grep ^'530 Login incorrect' | wc -l`

if [ ${IS_FTP_FAILED} -ne 0 ]
then
  echo "Ftp failed"
  sendmail ... page ...
fi

There will be an FTP code number for a success or every kind of failure
If you see a line starting with '226 ' then it's success
If you want to be notified for a failed FTP no matter what's the reason then check for count of lines starting with '226 ', if the count is zero then notify failure

If you want to know for login failure, find the FTP code (530 Login incorrect.) for this and search for this line

Thanks,
-srinivas yelamanchili
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

FTP log only shows FTP LOGIN FROM entry?

OS: Solaris 9 Configuration /etc/syslog.conf daemon.debug /etc/inetd.conf ftp stream tcp6 nowait root /usr/sbin/in.ftpd in.ftpd -A -l -d Found the ftp.log only generate those entries from other servers/hosts. Can we trace on all ftp entries either from/to the server? ... (6 Replies)
Discussion started by: KhawHL
6 Replies

2. Cybersecurity

Check login detail

As a root user i switch to a different user say "oratest". I would like to know the details like at what time did the switch ( su - oratest ) happen. Are there any logs to check this Thanks. (2 Replies)
Discussion started by: jjoy
2 Replies

3. UNIX for Dummies Questions & Answers

Check login details

As a root user i switch to a different user say "oratest". I would like to know the details like at what time did the switch ( su - oratest ) happen. Are there any logs to check this Thanks. (4 Replies)
Discussion started by: jjoy
4 Replies

4. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

5. Solaris

Check systems login

Hi All, In Solaris 10, how can I check back who is login to the systems by telnet, ssh and ftp in success or failed. I already check on /var/adm/messages but no details for all this. Hope your can help. Thanks. (1 Reply)
Discussion started by: mailbox80
1 Replies

6. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

7. UNIX for Advanced & Expert Users

Check existence of a login

Hi everybody, I need to check in C program wether a given login is known on the system. Is there any system function that could do this ? So far, all I could find is getpwnam(), which answers my problem by parsing the local password database. But won't work if a user is authenticated by... (10 Replies)
Discussion started by: xavier054
10 Replies

8. UNIX for Advanced & Expert Users

FTP login problem

I've just configured a server to my network (setting the ip, netmask, host file, etc...) and the server doesn't have any problem pinging another computer on the network. however when i try to connect to the server via ftp the root account can't log in, i made another account (a standard one that... (2 Replies)
Discussion started by: pasalagua
2 Replies

9. UNIX for Dummies Questions & Answers

Automated FTP to variable directory with error check

Hi, automated FTP that have error check and each product FTP will used the same userid/password to post(transfer) the file(s) from their <product> directory at UNIX to their <product> folder at Windows. such senarios as follows: NOTE: ======= ** Variable ** * The <product> is variable... (3 Replies)
Discussion started by: songtam
3 Replies

10. UNIX for Dummies Questions & Answers

FTP login failing

Please help. I am running Solaris 8 trying to get my FTP to work. When I try to access the FTP server from another computer on the network, it connects and prompts for a password. The username and password I set up do not work as well as my root account. Neither of the accounts are set up in the... (3 Replies)
Discussion started by: zbis12
3 Replies
Login or Register to Ask a Question