Need Script to check the FTP connection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Script to check the FTP connection
# 1  
Old 06-29-2015
Need Script to check the FTP connection

Hi,

I need a script which check the FTP connections, if its working fine then no issue. Incase not working fine then Trigger the mail.

Please help on this.

Thanks
# 2  
Old 06-29-2015
Welcome Keshav Kalra,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What do you describe as a failure? Is is failure to open the connection, failure to get a file, failure to put a file or something else?
  • What OS and version are you using?
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
  • How would you test this manually?
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.



Kind regards,
Robin
# 3  
Old 06-29-2015
Hi Robin,

Thanks for your reply..
Code:
#!/bin/bash 

root_ftp ( )
{
ftp -nvi server name <<EOF 
user ** **
pwd
!date
bye
EOF

RC=`echo "$?"`
}
echo -n "Checking FTP Service status  `date `"
root_ftp
echo $RC
if [[ $RC != 0 ]]
then 
mail -s "$(echo -e "FTP Alert\n content -Type:") "Mail ID"
else 
echo -n "No issues found `date `"
fi

Above one I have tried...But mail is not getting triggered.

Connection are getting prepared..but In case of failure I am not getting mail triggered.
In both the cases successful or failure I am getting "No issues found "

Last edited by Scott; 06-29-2015 at 02:01 PM.. Reason: Please use code tags
# 4  
Old 06-29-2015
Your problem here is that the ftp command will probably return code zero in most cases unless the connection fails to open at all.

You might do well to trap the output into a file and then read it afterwards. With the -v flag set as you already have, your should get status messages in the output. Those starting of value 400-999 followed by a space are errors. You have to exclude any messages that say bytes transferred though, as you may genuinely move a file of between 400 & 999 bytes and my simple check would generate an error.


I hope that this helps. Let me know if it's not clear,
Robin
# 5  
Old 06-29-2015
If your goal is just to see if the FTP service is running on the target machine you could try this script (also useful for testing other socket listening services like sftp, httpd, mySQL, etc).

Note: this is a simple test but less comprehensive that your attempt, as it won't pickup issues with user or password changes which could also cause any FTP transfer to still fail even though a server is listening.

Code:
#!/bin/bash
if timeout 10 bash -c 'cat < /dev/null > /dev/tcp/server_name/21'  2>/dev/null
then
  printf "%s" "No issues found `date `"
else
  mail -s "$(echo -e "FTP Alert\n content -Type:") "Mail ID"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check the connectivity of the DB through script, exit if no connection

check the connectivity of the DBs through script, script should exit if no connection and display the output as below. connectivity for DB1 is OK connectivity for DB2 is OK connectivity for DB3 is FAILED for DB in 1 2 3 do (sqlplus -s... (5 Replies)
Discussion started by: only4satish
5 Replies

2. Shell Programming and Scripting

simple while loop script to check a connection

Hi, I am completely new to shell scripting. Basically I am wanting to create a simple while loop script to check if a network connection is available from 'netstat -a' and if its present then output a character to the serial port. I think i am nearly there.. but need some assistance.. this is... (9 Replies)
Discussion started by: zippyzip
9 Replies

3. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

4. Shell Programming and Scripting

How do I write a ksh script that will check if all ftp files are received?

I am trying to code a ksh script that will check to see if all 26 incoming ftp files have been received before proceeding to the next function, which is to rename each file. Here is the pseudo-code of what I am trying to do: <<STEP_1>> IF all ALS files have been transmitted then... (2 Replies)
Discussion started by: doug145
2 Replies

5. Shell Programming and Scripting

need to check the file using ftp in a shell script

i need to write a shell script.. connecting to another server using ftp and check whether the file ter.txt is exists there or not. i have written scirpt partially,as i new to Unix. ftp -inv $FTPHOST > $TEMPFILE1 2> $TEMPFILE1 << EOF user $FTPUSER $FTPPW binary prompt ${CD} ls *.txt... (11 Replies)
Discussion started by: KiranKumarKarre
11 Replies

6. Shell Programming and Scripting

Script to check file update on ftp server

Hi everybody, Is there a way to do a stat of files on a ftp server? I have a database which is populated by the contents of these files. I want to setup a crontab to check if there has been an update to these files. If the file has been updated I will download it and then update my database. ... (2 Replies)
Discussion started by: z1dane
2 Replies

7. Shell Programming and Scripting

how to check DB connection in unix shell script

In the following script I need to find whether DB is established successfully or not. I need to find and display it. If <DB is connected successfully> then echo "DB connection success" else echo "DB connection failure" fi In the same way I need to do it for DB terminate. I don't... (1 Reply)
Discussion started by: kmanivan82
1 Replies

8. 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

9. UNIX for Dummies Questions & Answers

FTP Connection

Hi, Anyone encounter whereby when you FTP from an Unix server (Solaris 8) to another server (Window Server 2003), you tend to wait a long while when you do a "ls" and you get a timeout after that. However, when you FTP again and do a "ls", the result of "ls" shown immediately. All connection are... (5 Replies)
Discussion started by: ahlude
5 Replies

10. UNIX for Dummies Questions & Answers

Bash Script to check Remote Host Connection

Hi all, Can anyone tell/guide me how to check remote host is up/running using bash script? Thanks. Zulfiqar (5 Replies)
Discussion started by: zulfikarmd
5 Replies
Login or Register to Ask a Question