I have a code to connect to an FTP server...
When I paste the "RequestURI" in my IE, I enter the password etc and I can download the file from FTP no problem
When I run my code, I get the following error:
When I use "CoreFTP", I get the following error (however the file does get downloaded):
here's my code-snipped:
When I paste the "RequestURI" in my IE, I enter the password etc and I can download the file from FTP no problem
When I run my code, I get the following error:
Code:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
550 *** ERROR *** NO BATCHES FOR TRANSMISSION
When I use "CoreFTP", I get the following error (however the file does get downloaded):
Code:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
550 *** ERROR *** NO BATCHES FOR TRANSMISSION
here's my code-snipped:
Code:
private void Download(string file)
{
try
{
string uri = host + "/" + remoteDir + "/" + file;
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return;
}
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false; // <--- Also tried true
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); // <--- Error occurs
Stream responseStream = response.GetResponseStream();
FileStream writeStream = new FileStream(Path.Combine(localDestnDir, file), FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
writeStream.Close();
response.Close();
}
catch (WebException wEx)
{
this.DisplayMessage(wEx.Message);
this.DisplayMessage((wEx.Response as FtpWebResponse).StatusDescription);
}
catch (Exception ex)
{
this.DisplayMessage(ex.Message);
}
}