cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

check download file

check download file

alicera
Explorer | Level 3
Go to solution

If I get a link for dropbox and I use the 'wget' to download it.

How to check it if download successfully?

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

@alicera In addition to the method Здравко helpfully provided, you could use the /2/sharing/get_shared_link_metadata Dropbox API endpoint to retrieve the metadata for a shared link, or an error if the shared link is invalid.

View solution in original post

7 Replies 7

Greg-DB
Dropbox Staff
Go to solution

You can check the HTTP status code of the response to see what the result is. For example, a 200 indicates success.

alicera
Explorer | Level 3
Go to solution

wget -nc dropbox_url 

It will download other file.

 

Greg-DB
Dropbox Staff
Go to solution

I'm not sure I understand your latest message. Do you have a question a I can help with?

Здравко
Legendary | Level 20
Go to solution

Hi @alicera,

For any kind of error that might come up on command line, you can check the retrieved result. For most commands (including 'wget'), success is denoted by zero. Any different exit status means that something happens considered as a error. File not found (HTTP status 404) gets transformed to server issued an error response - exit status 8, for example.


@alicera wrote:

wget -nc dropbox_url 

It will download other file.


No, no another file will get downloaded, while 'dropbox_url' keeps the same. Keep in mind that in such a case existing file is NOT considered error! That's why you're getting success and probably got confused. 🙂 To force existing file consideration as an error, you can use something like:

wget -nc -O filename.ext dropbox_url

Where 'filename.ext' is the desirable file name (possibly path prepended). Now (after explicit destination pointing) a try downloading already existing file (probably downloaded before) will result in general error (exit status 1, no more 0), which you can check. 😉

Hope this helps.

alicera
Explorer | Level 3
Go to solution

https://unix.stackexchange.com/questions/474805/verify-if-a-url-exists

I use the method and give error dropbox link,

it is return link exist

Здравко
Legendary | Level 20
Go to solution

Ahh... @alicera, now I see what you mean.

You want to check not for error in transfer process or error because of existing (already) file, but link validity.

It's not so trivial cosa Dropbox links are dynamically generated and even when no real file exists link point to error message (as a content, it's still valid). That's why you are getting "200 OK" for both valid and invalid link (the error message is valid 🤫). But there is a workaround. 😉 When some link is invalid, error message gets back immediately. If your link points to real file, redirect is performed to the pointed file. You can exploit this. 'wget' perform redirects by default and that's why always succeeds. If you disable redirects, a "strange" situation will happen: valid links will result in error (can't redirect), but invalid will succeed (redirect doesn't needed). So, inverting the check logic is going let you distinguish valid to invalid links. 🙂 Use something like following template:

wget --method=HEAD -q --max-redirect 0 <some Dropbox shared link>
echo $?

The above just print resulting code (currently 0 for invalid link - inverted logic). You can check it in conditional expression too, of course.

Hope this helps.

Greg-DB
Dropbox Staff
Go to solution

@alicera In addition to the method Здравко helpfully provided, you could use the /2/sharing/get_shared_link_metadata Dropbox API endpoint to retrieve the metadata for a shared link, or an error if the shared link is invalid.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    alicera Explorer | Level 3
What do Dropbox user levels mean?