LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-08-2009, 04:31 AM   #1
dz-015
LQ Newbie
 
Registered: Apr 2009
Location: UK
Distribution: Red Hat Enterprise Linux Server release 5.2 (Tikanga) / Fedora 10 KDE Desktop
Posts: 6

Rep: Reputation: 0
Bash script to test for open FTP sessions from specific clients


Hi, I was hoping someone could point me in the right direction here!

I look after a server which accepts automatic overnight PASV FTP uploads from remote clients. When the uploads are complete, my Bash script copies the files to another location.

The problem is, my script needs to be a bit smarter when it comes to detecting active FTP sessions.

I was using:

Code:
netstat -n | grep ":21 " | grep ESTABLISHED
to test if there were active sessions, but came unstuck when a local user left an unrelated FTP session active. The result - my script hung around all night thinking there was an active upload from a remote client.

My server is behind a firewall, so remote clients all show an internal (NAT) address, so I can't differentiate by source IP address.

I can't install LSOF or FUSER for security reasons.

Is there a way I can test for active FTP sessions from specific users?

I am running Red Hat Enterprise Linux Server release 5.2 (Tikanga).

Thanks for reading!

DZ
 
Old 04-08-2009, 04:39 AM   #2
eco
Member
 
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
Hi,

Just a thought here but wouldn't using rsync solve your problems?

You could have a cron job that would rsync every hour and keep your copy up to date within an hour?

That way, no need for an elaborate script and rsync would only copy the changes and minimise on bandwidth.

Just a thought.
 
Old 04-08-2009, 04:44 AM   #3
dz-015
LQ Newbie
 
Registered: Apr 2009
Location: UK
Distribution: Red Hat Enterprise Linux Server release 5.2 (Tikanga) / Fedora 10 KDE Desktop
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks eco, but I can't alter anything about the way the remote machines transfer the files. The machines are maintained by a third party and they would want paying for making any changes!

I need to work with what I've got...

DZ
 
Old 04-08-2009, 04:48 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,119

Rep: Reputation: 218Reputation: 218Reputation: 218
Hi

I've been using Pure-FTPd for a similar task - http://www.pureftpd.org/project/pure-ftpd

It has a feature where you can configure it to run a script on all uploads when the upload is done. That script will get the name of the uploaded file as parameter. So then checking if the upload is in progress is not necessary.

It also has a command "pure-ftpwho" that shows what is happening - with an optional -x parameter to give the information in XML format so it's easily parsed by a script.

Last edited by Guttorm; 04-08-2009 at 04:49 AM.
 
Old 04-08-2009, 04:56 AM   #5
dz-015
LQ Newbie
 
Registered: Apr 2009
Location: UK
Distribution: Red Hat Enterprise Linux Server release 5.2 (Tikanga) / Fedora 10 KDE Desktop
Posts: 6

Original Poster
Rep: Reputation: 0
Guttorm,

Thanks for that - I'm using vsftpd server and need to work with that.
Pure-FTPd looks good, but I'm stuck with vsftpd.

There must be a way to do this by looking for open files, running processes, netstat results?

Thanks,

DZ
 
Old 04-08-2009, 05:05 AM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,119

Rep: Reputation: 218Reputation: 218Reputation: 218
Hmm. Well I don't know much about vsftp. But what about reading its log file? Then do some actions when the files are uploaded...
 
Old 04-08-2009, 05:15 AM   #7
dz-015
LQ Newbie
 
Registered: Apr 2009
Location: UK
Distribution: Red Hat Enterprise Linux Server release 5.2 (Tikanga) / Fedora 10 KDE Desktop
Posts: 6

Original Poster
Rep: Reputation: 0
Yeah, I could do that. The last line logged when a transfer completes is:

Code:
[username] FTP response: Client "xxx.xxx.xxx.xxx", "221 Goodbye."
I could look for the string "Goodbye" in the last line in the vsftp.log and wait if it isn't found. That doesn't get around the problem of an internal user leaving an FTP session active..

As I said earlier, the Client IP address is always the internal (NAT) address, so I can't differentiate based on that.

Another method I considered was looking for files modified in last n seconds in the ftp area and wait..

I'm convinced there must be a better way of doing this - maybe not!

Thanks for suggestions so far,

DZ

Last edited by dz-015; 04-08-2009 at 05:19 AM.
 
Old 04-09-2009, 06:33 AM   #8
eco
Member
 
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
Just a late thought... you could terminate an ftp session after 10 minutes of inactivity.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access authenticating FTP sites using FTP Clients on XP clients via SQUID munirg2003 Linux - Networking 2 06-12-2007 10:58 PM
Bash script to search for specific pattern? jimyg10 Programming 22 05-18-2007 01:02 PM
help with Bash script (test) Benanzo Linux - Software 1 04-09-2007 03:18 AM
BASH script to copy specific files ScottReed Linux - Software 5 07-20-2006 11:08 AM
bash script 'test' question linmix Programming 5 11-29-2005 11:49 AM


All times are GMT -5. The time now is 02:35 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration