<commit_before>﻿using System;
using System.Net;
using System.Net.Sockets;

namespace System.Net.FtpClient {
	public class FtpActiveStream : FtpDataStream {
		public override bool Execute(string command) {
			// if we're already connected we need
			// to reset ourselves and start over
			if(this.Socket.Connected) {
				this.Close();
			}

			if(!this.Socket.Connected) {
				this.Open();
			}

			try {
				this.CommandChannel.LockCommandChannel();
				this.CommandChannel.Execute(command);

				if(this.CommandChannel.ResponseStatus && !this.Socket.Connected) {
					this.Accept();
				}

				return this.CommandChannel.ResponseStatus;
			}
			finally {
				this.CommandChannel.UnlockCommandChannel();
			}
		}

		protected void Accept() {
			Socket s = this.Socket.Accept();

			this.Socket.Close();
			this.Socket = null;
			this.Socket = s;
		}

		protected override void Open(FtpDataChannelType type) {
			string ipaddress = null;
			int port = 0;

			this.Socket.Bind(new IPEndPoint(((IPEndPoint)this.CommandChannel.LocalEndPoint).Address, 0));
			this.Socket.Listen(1);<commit_msg>Fixed bug in Active mode transfers that caused the code to hang when accepting the incoming connection.<commit_after>﻿using System;
using System.Net;
using System.Net.Sockets;

namespace System.Net.FtpClient {
	public class FtpActiveStream : FtpDataStream {
		public override bool Execute(string command) {
			// if we're already connected we need
			// to reset ourselves and start over
			if(this.Socket.Connected) {
				this.Close();
			}

			if(!this.Socket.Connected) {
				this.Open();
			}

			try {
				this.CommandChannel.LockCommandChannel();
				this.CommandChannel.Execute(command);

				if(this.CommandChannel.ResponseStatus && !this.Socket.Connected) {
					this.Accept();
				}

				return this.CommandChannel.ResponseStatus;
			}
			finally {
				this.CommandChannel.UnlockCommandChannel();
			}
		}

		protected void Accept() {
			this.Socket = this.Socket.Accept();
		}

		protected override void Open(FtpDataChannelType type) {
			string ipaddress = null;
			int port = 0;

			this.Socket.Bind(new IPEndPoint(((IPEndPoint)this.CommandChannel.LocalEndPoint).Address, 0));
			this.Socket.Listen(1);
{'fraction_non_alphanumeric': 0.11383219954648525, 'fraction_numerical': 0.0027210884353741495, 'mean_word_length': 3.511247443762781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372264', 'n_tokens_mistral': 816, 'n_tokens_neox': 659, 'n_words': 147}