Ankit Agarwal

Ankit Agarwal

  • NA
  • 379
  • 254.2k

The remote server returned an error (550) file unavailable

Oct 25 2016 12:53 AM
Hello,
 
The remote server returned an error (550) file unavailable (e.g. file not found no access).
 
When i am downloading two files one is 21 bytes only Date.txt file and another one around 2 GB .zip file.
Zip file downloading successfully but when Date.txt was downloading so its getting error:
Please help me.

How it can be resolve?
 
I am trying this code from file download from FTP.:-
 
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string[] files = ReadFileList();
FTPSettings.IP = "xx.xx.xxx.xxx/TextureData";
FTPSettings.UserID = "xxxx";
FTPSettings.Password = "xxx";
//FtpWebRequest reqFTP = null;
//Stream ftpStream = null;
foreach (string file in files)
{
//string fileName = e.Argument.ToString();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + FTPSettings.IP + "/" + file);
request.Credentials = new NetworkCredential(FTPSettings.UserID, FTPSettings.Password);
request.Method = WebRequestMethods.Ftp.GetFileSize;
request.Proxy = null;
long fileSize; // this is the key for ReportProgress
using (WebResponse resp = request.GetResponse())
fileSize = resp.ContentLength;
request = (FtpWebRequest)WebRequest.Create("ftp://" + FTPSettings.IP + "/" + file);
request.Credentials = new NetworkCredential(FTPSettings.UserID, FTPSettings.Password);
request.Method = WebRequestMethods.Ftp.DownloadFile;
using (FtpWebResponse responseFileDownload = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = responseFileDownload.GetResponseStream())
using (FileStream writeStream = new FileStream(@"C:\Program Files (x86)\xxxx\" + file, FileMode.Create))
{
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
int bytes = 0;
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
bytes += bytesRead;// don't forget to increment bytesRead !
int iProgress = 0;
int totalSize = (int)(fileSize) / 1000; // Kbytes
if (totalSize > 0)
{
iProgress = (bytes / 1000) * 100 / totalSize;
}
backgroundWorker1.ReportProgress(iProgress, totalSize);
}
}
string zipFileExtension = Path.GetExtension(file);
if (zipFileExtension == ".zip")
{
string zipToUnpack = @"C:\Program Files (x86)\xxxx\" + file;
string unpackDirectory = @"C:\Program Files (x86)\xxxx\";
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
foreach (ZipEntry ze in zip1)
{
ze.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
}
}
}
public static class FTPSettings
{
public static string IP { get; set; }
public static string UserID { get; set; }
public static string Password { get; set; }
}
public string[] ReadFileList()
{
//Debugger.Break();
string[] mydownloadFiles;
StringBuilder myresult = new StringBuilder();
//WebResponse myresponse = null;
StreamReader myreader = null;
FtpWebRequest myreqFTP = null;
try
{
FTPSettings.IP = "xx.xx.xxx.xxx/TextureData";
FTPSettings.UserID = "xxxx";
FTPSettings.Password = "xxxx";
myreqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + FTPSettings.IP + "/"));
myreqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
myreqFTP.UseBinary = true;
myreqFTP.Credentials = new NetworkCredential(FTPSettings.UserID, FTPSettings.Password);
FtpWebResponse response = (FtpWebResponse)myreqFTP.GetResponse();
myreader = new StreamReader(response.GetResponseStream());
string myline = myreader.ReadLine();
while (myline != null)
{
myresult.Append(myline);
myresult.Append("\n");
myline = myreader.ReadLine();
}
// to remove the trailing '\n'
myresult.Remove(myresult.ToString().LastIndexOf('\n'), 1);
return myresult.ToString().Split('\n');
}
catch (Exception ex)
{
if (myreader != null)
{
myreader.Close();
}
mydownloadFiles = null;
return mydownloadFiles;
}
 
Please help me.

Thanks in Advance.
Ankit Agarwal
Software Engineer
 
 

Answers (4)