I am trying to connect my app to read a document hosted in my FTP server, I am using FileZilla, my app is hosted in Azure. But it seems it cannot connected. I have a public IP, in localhost my app runs fine but when it's online it failed. This is the code I am using to connect the app with my FTP server.
public static void getExcelFromFTP(string destinationFile)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://100.100.100.0/folder/file.xlsx");
request.KeepAlive = true;
request.UseBinary = true;
request.Credentials = new NetworkCredential(@"username", "password");//FTP Server credentials
request.Method = WebRequestMethods.Ftp.DownloadFile;
Stream reader = request.GetResponse().GetResponseStream();
FileStream fileStream = new FileStream(destinationFile, FileMode.Create);
int bytesRead = 0;
byte[] buffer = new byte[2048];
while (true)
{
bytesRead = reader.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
fileStream.Write(buffer, 0, bytesRead);
}
fileStream.Close();
}
Can somebody help me out with this issue? Thanks in advance.
The only thing what I had to it was to make sure that links were written correctly at the moment of attach files to the email.