473,414 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

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] << 8) + 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;
}

Mar 18 '06 #1
0 2225

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Data | last post by:
In my project I want to execute some commands on the remote machine. I am using .Net Remoting to achieve this. My server which is an exe is copied on the remote machine and it receives command from...
5
by: Data | last post by:
In my project I want to execute some commands on the remote machine. I am using .Net Remoting to achieve this. My server which is an exe is copied on the remote machine and it receives command from...
8
by: hufaunder | last post by:
I have a website that consumes a webservice. Both of them are in the Default Website folder. I can execute the service without any problem when I go to the test page http://localhost/Service.asmx....
5
by: OJ | last post by:
Hi, I am at a loss here, I have a c# asp.net website which connects to a remote SQL Server 2000 db via a connection string. If I set the website up in the filesystem and use the inbuilt cassini...
1
by: Vikram S | last post by:
Hi All, I have an ASP.NET 2.0 web application on a web server and a separate machine for SQL Server 2000 Database. I am using a Connectionstring based on Sql Authentication to connect to the...
1
by: urvika | last post by:
I have an ASP.NET 2.0 web application on a web server and a separate machine for SQL Server 2000 Database. I am using a Connectionstring based on Sql Authentication to connect to the the SQL 2000...
0
by: Homer | last post by:
Hi, I got "InnerException: Unable to connect to remote server"..."No connection could be made because the target machine actively refused it" when I attempted to send an email through my...
0
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
I have a TCPListener in a Service. Works fine. But if I stop it and manually restart it, I get No connection could be made because the target machine actively refused it. in my app with the...
3
by: Adhal | last post by:
Hi, I am using remoting to pass in parameters from new launches of an application. So basically I have only one instance of the application and I am using remoting to pass the parameters. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.