As far as I understand your question, do you want to upload the file to another remote server (so this is not another server that is on the same network as your web server)? In this case, you can do a couple of different things. The easiest way is to start by loading your server with a regular file, and then your server will send the file via FTP to another remote server:
string fileName = Path.Combine("<path on your server", FileUpload1.FileName);
FileUpload1.SaveAs(fileName);
using(System.Net.WebClient webClient = new System.Net.WebClient())
{
webClient.UploadFile(
New Uri("ftp://remoteserver/remotepath/" + FileUpload1.FileName),
localFile);
}
... or he can do it in one step:
using(System.Net.WebClient webClient = new System.Net.WebClient())
{
webClient.UploadData(
New Uri("ftp://remoteserver/remotepath/" + FileUpload1.FileName),
FileUpload1.FileBytes);
}
(I am not trying to execute this code, so there might be some errors in it ...)
Update: I noticed that I was mistaken in believing that the UploadXXX WebClient methods were static ...
source
share