LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [bash] Remote file existence check (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bbash%5D-remote-file-existence-check-613506/)

danket 01-14-2008 11:55 AM

[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

bigrigdriver 01-14-2008 12:28 PM

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


danket 01-14-2008 12:36 PM

Quote:

Originally Posted by bigrigdriver (Post 3022172)
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.

anomie 01-14-2008 01:49 PM

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

danket 01-14-2008 02:32 PM

There's nothing wrong with wget :) But thanks anyway, you put me on right track :)

colucix 01-14-2008 04:39 PM

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.


All times are GMT -5. The time now is 04:19 PM.