Exemplo n.º 1
0
 /// <summary>Creates a data socket.</summary>
 /// <param name="Filename">Specifies the local filename.</param>
 /// <param name="Filemode">Specifies the file mode.</param>
 /// <param name="StreamDirection">Specifies the direction of the stream.</param>
 /// <param name="AppendFrom">Specifies where to append from.</param>
 /// <returns>Returns True if it was successfully created, False otherwise.</returns>
 private bool CreateDataSocket(string Filename, DataConnection.FileModes Filemode, DataConnection.StreamDirections StreamDirection, long AppendFrom)
 {
     try {
         dataSocket                 = new DataConnection();
         dataSocket.Filename        = Filename;
         dataSocket.DownloadToFile  = (Filename != "");
         dataSocket.AppendFrom      = AppendFrom;
         dataSocket.FileMode        = Filemode;
         dataSocket.StreamDirection = StreamDirection;
         dataSocket.DataSent       += new DataConnection.DataSentHandler(DataSent);
         dataSocket.DataReceived   += new DataConnection.DataReceivedHandler(DataReceived);
         if (passiveTransfers)
         {
             SendCommand("PASV");
             if (lastResponseType == 2)
             {
                 int BeginPos = lastResponse.IndexOf("(");
                 int EndPos   = lastResponse.IndexOf(")", BeginPos + 1);
                 if (BeginPos > 0 && EndPos > 0)
                 {
                     string [] Output = lastResponse.Substring(BeginPos + 1, EndPos - BeginPos - 1).Split(',');
                     if (Output.Length == 6)
                     {
                         passiveEndPoint           = new IPEndPoint(IPAddress.Parse(Output[0] + "." + Output[1] + "." + Output[2] + "." + Output[3]), int.Parse(Output[4]) * 256 + int.Parse(Output[5]));
                         dataSocket.RemoteEndPoint = passiveEndPoint;
                         dataSocket.Connect();
                     }
                 }
             }
         }
         else
         {
             dataSocket.Listen();
         }
     } catch {
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
 /// <summary>Creates a data socket.</summary>
 /// <param name="StreamDirection">Specifies the direction of the stream.</param>
 /// <returns>Returns True if it was successfully created, False otherwise.</returns>
 private bool CreateDataSocket(DataConnection.StreamDirections StreamDirection)
 {
     return(CreateDataSocket("", DataConnection.FileModes.Overwrite, StreamDirection, 0));
 }