private void ConnectDataSocket() // #######################################
{
if (data_sock != null) // already connected (always so if passive mode)
return;
try
{
#if (FTP_DEBUG)
Console.WriteLine("Accepting the data connection.");
#endif
data_sock = listening_sock.Accept(); // Accept is blocking
listening_sock.Close();
listening_sock = null;
if (data_sock == null)
{
throw new Exception("Winsock error: " +
Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error()));
}
#if (FTP_DEBUG)
Console.WriteLine("Connected.");
#endif
}
catch (Exception ex)
{
throw new Exception("Failed to connect for data transfer: " + ex.Message);
}
}