-1

I have two different websites running on two different servers with URL say http://192.168.0.102:1004 and http://192.168.0.122:1005.

Now i am trying to copy a image file from http://192.168.0.102:1004 to http://192.168.0.122:1005 using following code

if (File.Exists("http://192.168.0.122:1005/Assets/Images/Stores/14/14_Logo.png"))
{
    File.Copy("http://192.168.0.122:1005/Assets/Images/Stores/14/14_Logo.png", "http://192.168.0.102:1004/Assets/Images/Stores/14/14_Logo.png", true);
}

But If condition always return me false. However if i copy this URL in browser, it render me desired image on page.

If file exists, i need to copy it from source domain to target domain.

How to achieve this ?

Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83

1 Answers1

1

You cannot use the File object for these kinds of checks.

Please see the answer on: can I check if a file exists at a URL?

TL;DR You should check if the server returns a 200 (OK) using the HttpWebRequest object.

Community
  • 1
  • 1
Peter R
  • 364
  • 2
  • 11
  • Thanks for your reply but this does not answer my question fully. How do i copy image from source domain to target domain then? – Rajeev Kumar Mar 10 '16 at 12:06
  • @RajeevKumar Download the image and save to disk – Alex Mar 10 '16 at 12:08
  • 2
    You should look at various protocols. You can't simply use HTTP like that. You need to set up a server (with authentication) and decide exactly how to send files (with POST or PUT). SFTP is probably a more sensible protocol. – Joe Mar 10 '16 at 12:08