LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-14-2008, 11:55 AM   #1
danket
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Rep: Reputation: Disabled
[bash] Remote file existence check


Hi!
Would anyone have an idea how (using bash script) to check if remote file exists? I'd need to know if file ftp://user:pass@server.com/dir/somefile.txt has already been created, if so, wget would down it. I just need a command which would return 'true' or 'false'.
I have experimented with test and wget, but it's a wrong path, I guess. I'm getting kinda confused :/
Thanks in advance,
Dan

Last edited by danket; 01-14-2008 at 11:59 AM.
 
Old 01-14-2008, 12:28 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,765

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Maybe something like
Code:
if [ -e ftp://user:pass@server.com/dir/somefile.txt ]; then
     wget ftp://user:pass@server.com/dir/somefile.txt
fi
 
Old 01-14-2008, 12:36 PM   #3
danket
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bigrigdriver View Post
Maybe something like
Code:
if [ -e ftp://user:pass@server.com/dir/somefile.txt ]; then
     wget ftp://user:pass@server.com/dir/somefile.txt
fi
Thanks for the tip, but 'test -e' works only on local file system, I'd have remote fs mounted locally, which is immposible as of today.
 
Old 01-14-2008, 01:49 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
What's wrong with just attempting to wget it? If it's not there, wget errors out...

To test for the presence of the file you'd have to authenticate anyway (based on what you've shown here).
 
Old 01-14-2008, 02:32 PM   #5
danket
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Original Poster
Rep: Reputation: Disabled
There's nothing wrong with wget :) But thanks anyway, you put me on right track :)
 
Old 01-14-2008, 04:39 PM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
You may also consider the following options to wget:
Quote:
--tries=number
Set number of retries to number. Specify 0 or inf for infinite retrying.
The default is to retry 20 times, with the exception of fatal errors like
"connection refused" or "not found" (404), which are not retried.

--waitretry=seconds
If you don’t want Wget to wait between every retrieval, but only between
retries of failed downloads, you can use this option. Note that this option
is turned on by default in the global wgetrc file.
 
  


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
FTP scripts check remote servers file manish_meet_in Linux - General 1 02-28-2007 02:07 PM
[Question] Check File existence hbinded Programming 3 12-19-2006 05:15 PM
check for file existence ignoring case sensitive rammohhan2000 Programming 3 06-13-2006 03:12 PM
Checking existence on remote server MikeAtVillage Programming 2 04-03-2006 11:16 AM
check for existence of file j-me Linux - Newbie 5 07-29-2003 07:58 AM


All times are GMT -5. The time now is 06:32 PM.

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