I'm working on ASP.NET project and I need a function where a user downloads a file from FTP server and saved to his/her local machine. The files are in different FTP server and the ASP.NET project is hosted in different server. So to download, I passed the server address and FTP credentials. It works when I runs the project on localhost, but when I upload the project to server and try to download from the hosted site, the files doesn't download and save to my pc.
This my code below
string inputfilepath = @"C:\Temp\"+_filename;
string ftphost = "advhost11@14.182.126.8:3131";
string ftpfilepath = _filename;
string ftpfullpath = "ftp://" + ftphost +"/"+ ftpfilepath;
using (WebClient request = new WebClient())
{
request.Credentials = new NetworkCredential("username", "password");
byte[] fileData = request.DownloadData(ftpfullpath);
Directory.CreateDirectory(Path.GetDirectoryName(inputfilepath));
using (FileStream file = File.Create(inputfilepath))
{
file.Write(fileData, 0, fileData.Length);
file.Close();
}
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Receipt downloaded and saved at C:\\\\Temp\\\\BankTransfer.');", true);
}