I am trying to download a file from a MOXA UC8410 over FTP. My code is not working. Here is my code:
void download2()
{
Uri serverUri = new Uri("ftp://169.254.1.1/CFDisk/PCPACM/pcpacm.ini");
// The serverUri parameter should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
}
// Get the object used to communicate with the server.
WebClient request = new WebClient();
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("admin", "admin");
try
{
byte[] newFileData = request.DownloadData(serverUri.ToString());
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
//Console.WriteLine(fileString);
}
catch (WebException e)
{
// Console.WriteLine(e.ToString());
MessageBox.Show(e.Response + e.Message);
}
}
I have also tried this :
void download()
{
try
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://169.254.1.1:21/CFDisk/PCPACM/pcpacm.ini"));
// using admin as the username and admin as the passward.
request.Credentials = new NetworkCredential("admin", "admin");
//request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
processingfile(reader);
responseStream.Close();
reader.Close();
}
catch (Exception e2)
{
MessageBox.Show("Not connected" , e2.Message);
}
}
The code get to
Stream responseStream = response.GetResponseStream();
and it just stops, it never goes to the next line.
output says:
The thread 0x175c has exited with code 259 (0x103).
The thread 0x212c has exited with code 259 (0x103).
which does not help.
I can ftp to the MOXA UC8410 using the command prompt and I can download the file using FileZilla but not using my code. There is no firewall on the Moxa UC8410, so something most be wrong with my code.
UpDate: UpDATE It is working !!!
but only if I go to local Area Connection Properties and change Internet Protocol Version 4(tcp/IPv4) to
use the following IP address:
IP address: 169.254.1.5
Subnet mask: 225.225.0.0
does anyone know why? and is there a way I can fix it where I do not have to do that ?
Why do I have to put them on the same sub domain ?