error 150 in ftp app

19/04/2010 - 22:17 por JSMD | Informe spam
Hi guys,

I'm getting a problem when I try to download sometimes files from a FTP
Server. The error I get is 150.
Can anyone tell me how can I solve it?

The code I use to connect and donwload the files is:


public string Download(string fileName,ftpAccount Account)
{
FtpWebRequest reqFTP;
string messageResult = "";
try
{
FileStream outputStream = new
FileStream(Account.Path+Account.LocalOutbox + fileName, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new
Uri("ftp://" + Account.IPAddress+ Account.RemoteOutbox+ fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new
NetworkCredential(Account.UserName,Account.Password);

SSL_Certificate = Account.Certificate;

reqFTP.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(myCertificateValidation);

FtpWebResponse response =
(FtpWebResponse)reqFTP.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)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
messageResult = "File downloaded successfully: " + fileName
+ " from ftp://" + Account.IPAddress + Account.RemoteOutbox;

//Deleting the file
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new
Uri("ftp://" + Account.IPAddress + Account.RemoteOutbox + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(Account.UserName,
Account.Password);
SSL_Certificate = Account.Certificate;
if (Account.Protocol != "FTP")
{
reqFTP.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(myCertificateValidation);
}
response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();

messageResult += "File removed successfully: " + fileName
+ " from ftp://" + Account.IPAddress + Account.RemoteOutbox;

}
catch (Exception ex)
{
messageResult = "File not downloaded: " + fileName + ".
Error: " + ex.Message;
}
return messageResult;
}
 

Leer las respuestas

#1 RFOG
20/04/2010 - 09:13 | Informe spam
It seems you need to connect/download in Passive Mode.

Or perhaps this can help you:
http://www.rhinosoft.com/respcode.asp?resp0&


BTW, this is a Spanish Talking news forum. For English ones yon need to
connect to microsoft.public.dotnet.languages.csharp



On Mon, 19 Apr 2010 23:17:01 +0300, JSMD
wrote:

Hi guys,

I'm getting a problem when I try to download sometimes files from a FTP
Server. The error I get is 150.
Can anyone tell me how can I solve it?

The code I use to connect and donwload the files is:


public string Download(string fileName,ftpAccount Account)
{
FtpWebRequest reqFTP;
string messageResult = "";
try
{
FileStream outputStream = new
FileStream(Account.Path+Account.LocalOutbox + fileName, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new
Uri("ftp://" + Account.IPAddress+ Account.RemoteOutbox+ fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new
NetworkCredential(Account.UserName,Account.Password);

SSL_Certificate = Account.Certificate;

reqFTP.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(myCertificateValidation);

FtpWebResponse response > (FtpWebResponse)reqFTP.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)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
messageResult = "File downloaded successfully: " +
fileName
+ " from ftp://" + Account.IPAddress + Account.RemoteOutbox;

//Deleting the file
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new
Uri("ftp://" + Account.IPAddress + Account.RemoteOutbox + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new
NetworkCredential(Account.UserName,
Account.Password);
SSL_Certificate = Account.Certificate;
if (Account.Protocol != "FTP")
{
reqFTP.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(myCertificateValidation);
}
response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();

messageResult += "File removed successfully: " +
fileName
+ " from ftp://" + Account.IPAddress + Account.RemoteOutbox;
}
catch (Exception ex)
{
messageResult = "File not downloaded: " + fileName + ".
Error: " + ex.Message;
}
return messageResult;
}





Microsoft Visual C++ MVP => http://geeks.ms/blogs/rfog
Todos los cerebros del mundo son impotentes contra cualquier estupidez que
esté de moda

Preguntas similares