tags:

views:

54

answers:

1

I'm using .Net.

Is it possible for a web form to upload an image from a web or FTP server? The files I need to submit are on the web. If this is possible, code snippet is appreciated.

+3  A: 

Yes, it is possible.

You can use the WebClient class to interact with other web servers in .Net server-side code.

For example:

using(var client = new WebClient())
    client.UploadFile("ftp://server/path", @"C:\path\to\file");

If the file is on a different website, you can write the following:

using(var client = new WebClient())
     client.UploadData("ftp://server/path", client.DownloadData("http://server/path"));

You can read and write FTP, HTTP, and HTTPS urls interchangeably.

SLaks
Can you explain this further? I need to POST (web form) the file.
StackOverflowNewbie
You can POST the file by replacing `ftp://server/path` with the full URL that you want to POST to.
SLaks
And what if I need to pass other parameters, too? For example, in an email application, one would need to pass a "to" address, a "subject", a "body", and a file attachment.
StackOverflowNewbie