Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > FTP :No connection could be made because the target machine actively refused it

Reply
Thread Tools

FTP :No connection could be made because the target machine actively refused it

 
 
gaurav tyagi
Guest
Posts: n/a
 
      03-18-2006
i am trying to downlosd frles from a local ftp server in my network .
here i am able to connect to server
but to get file list from server i send "PASV" command it retuns some
value which is not 227.
agian i pass "PASV" command then it returns correct value which is 227.
now i have ip of server and port number so i try to create socket for
connection but this time it send me a exception "No connection could
be made because the target machine actively refused it"
problem 1. "PASV " commmand work in second loop . wrong replay in first
call
problem 2. not creating socket.

all code is in C#

private Socket createDataSocket()
{
this.sendCommand("PASV");

if ( this.resultCode != 227 ) throw new
FtpException(this.result.Substring(4));

int index1 = this.result.IndexOf('(');
int index2 = this.result.IndexOf(')');

string ipData = this.result.Substring(index1+1,index2-index1-1);

int[] parts = new int[6];

int len = ipData.Length;
int partCount = 0;
string buf="";

for (int i = 0; i < len && partCount <= 6; i++)
{
char ch = char.Parse( ipData.Substring(i,1) );

if ( char.IsDigit(ch) )
buf+=ch;

else if (ch != ',')
throw new FtpException("Malformed PASV result: " + result);

if ( ch == ',' || i+1 == len )
{
try
{
parts[partCount++] = int.Parse(buf);
buf = "";
}
catch (Exception ex)
{
throw new FtpException("Malformed PASV result (not supported?): "
+ this.result, ex);
}
}
}

string ipAddress = parts[0] + "."+ parts[1]+ "." + parts[2] + "." +
parts[3];

int port = (parts[4] << + parts[5];

Socket socket = null;
IPEndPoint ep = null;

try
{
socket = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
socket.Connect(ep);
}
catch(Exception ex)
{
// doubtfull....
if ( socket != null && socket.Connected ) socket.Close();

throw new FtpException("Can't connect to remote server", ex);
}

return socket;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP Connection Refused By Remote Host =?Utf-8?B?cmF6b3I=?= Windows 64bit 5 08-23-2007 07:48 PM
smtp error: unable to connect to remote server...No connection could be made because the target machine actively refused it Homer ASP .Net 2 08-13-2007 05:39 PM
No connection could be made because the target machine actively refused it hufaunder@yahoo.com ASP .Net 9 05-10-2007 07:30 AM
No connection could be made because the target machine actively refused it hufaunder@yahoo.com ASP .Net Web Services 8 07-25-2006 07:42 PM
Project could not be opened because a language-specific compiler could not be instantieted Roxanne ASP .Net 0 07-04-2003 10:22 AM



Advertisments