LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-09-2009, 11:40 AM   #1
jlarsen
Member
 
Registered: Jan 2005
Location: Dallas, TX
Distribution: Slackware 14.1
Posts: 79

Rep: Reputation: 15
exit ftp session if connection is not made


A couple quick notes to keep this on track:
I do not control the network or ftp host
FTP is the protocol that must be used - not my decision

I have a process that does some work, then calls ftp for a file transfer, then does more work after ftp is finished. The problem is that sometimes the ftp host will not be available and I get something like this:

Code:
guy@testserver:~$ ftp -i 1.2.3.4
ftp: connect: Connection timed out
ftp>
At this point the ftp session does not exit and control never goes back to the process that called it. This causes both ftp and the first process to hang.

1. Is there a way to call tell the ftp client to exit after this error or a certain amount of time?

or if that is not possible

2. Any ideas how to monitor the time a process has been running (by name or PID) and terminate the process if it has been running too long? - prefer bash or C.

Thanks,
 
Old 12-09-2009, 12:12 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
How do you run the ftp commands from the script? Does an explicit quit or bye command at the end of the command list solve the problem?
 
Old 12-09-2009, 12:51 PM   #3
jlarsen
Member
 
Registered: Jan 2005
Location: Dallas, TX
Distribution: Slackware 14.1
Posts: 79

Original Poster
Rep: Reputation: 15
Code:
ftp -i xxx.xxx.xxx.xxx
It then uses a .netrc file to get the commands - which does end with a quit command, but from what I can tell the .netrc file never gets used since the machine does not connect.

Last edited by jlarsen; 12-09-2009 at 12:53 PM. Reason: avoid confusion.....
 
Old 12-09-2009, 01:12 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
First be sure the .netrc file has proper permissions. They should be:
Code:
-rw------- 1 user group 51 Jul 11 18:30 .netrc
Then be sure the name or IP address specified in one of the machine tokens inside the .netrc, matches exactly the name or the IP address specified in the ftp command line.

If none of this works, you can always put the command list inside the script itself and use option -n to avoid auto-login (that is the .netrc file is ignored), for example:
Code:
ftp -ni xxx.xxx.xxx.xxx << EOS
user username password
cd /path/to/remote/dir
get filename
bye
EOS
Note that you can assign the same permissions -rw------- to the script, so that you can (at least) avoid other users read the password written in the scrip itself.
 
Old 12-09-2009, 01:50 PM   #5
jlarsen
Member
 
Registered: Jan 2005
Location: Dallas, TX
Distribution: Slackware 14.1
Posts: 79

Original Poster
Rep: Reputation: 15
Thanks, but the .netrc part works fine, except when the ftp host becomes unreachable. I believe the commands in the .netrc file only get executed upon successful login to the ftp host listed by machine.

If you would like to try put this in .netrc (and of course chmod 600 .netrc):

Code:
machine 1.2.3.4
login guy
password somepassword

macdef init
ascii
quit
then:

ftp -i 1.2.3.4

It will not connect and leave you at a ftp session prompt.


Unfortunately the second option will not work either. It is a C program and the ftp instructions can not be hard coded as they are different for every server it runs on.
 
  


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
How to gracefully exit a VNC/NX session? haertig Linux - Software 4 08-21-2009 01:03 AM
Xsession:warning:unable to write to /tmp;X session may exit with an error gabsik Linux - Desktop 9 05-31-2007 10:51 PM
How do I exit a full screen Tsclinet session? fabre Linux - Software 2 03-15-2006 07:09 AM
Exit Session - Sort Of... GNewbie MEPIS 2 02-01-2006 02:00 AM
Exit X Window System session Azzath Linux - Software 4 01-04-2005 03:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:17 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration