I had a little problem while downloading a file from FTP. I'm getting a error that says "the remote server returned an error (550) File unavailable (e.g, file not found, no access)."
The code is below:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btntamam_Click(object sender, EventArgs e)
{
FtpWebRequest FTP;
try
{
FileStream SR = new FileStream("C:\\asd" + "\\list.gz", FileMode.Create);
FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://xx.x.xx.xxx/" + "list.gz"));
FTP.Credentials = new NetworkCredential("username", "pass");
FTP.Method = WebRequestMethods.Ftp.DownloadFile;
FTP.UseBinary = true;
FtpWebResponse response = (FtpWebResponse)FTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
SR.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
SR.Close();
response.Close();
MessageBox.Show("File Downloaded!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
}
}
The code seems to be working, but it's unable to download the file I want. I've searched a lot but could not find any solutions..