LinuxQuestions.org
Help answer threads with 0 replies.
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, 12:55 PM   #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 12:59 PM.
 
Old 01-14-2008, 01:28 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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, 01: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, 02:49 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
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, 03: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, 05:39 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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 03:07 PM
[Question] Check File existence hbinded Programming 3 12-19-2006 06:15 PM
check for file existence ignoring case sensitive rammohhan2000 Programming 3 06-13-2006 04:12 PM
Checking existence on remote server MikeAtVillage Programming 2 04-03-2006 12:16 PM
check for existence of file j-me Linux - Newbie 5 07-29-2003 08:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:56 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
Open Source Consulting | Domain Registration