Ejemplo n.º 1
0
 public FTPDataConnection(IFTPConnection conn)
 {
     _conn = conn;
     _transType = conn.TransferType;
     set_transfer_type(conn, _transType);
     _conn.Lock();
     set_up_data_connection(conn);
 }
Ejemplo n.º 2
0
        public int DeleteFile(IFTPConnection connection, string remoteFileName)
        {
            connection.Lock();
            int returnValue = 0;
            string[] tempMessageList = connection.SendCommand("DELE " + remoteFileName);

            returnValue = FTPUtilities.GetMessageReturnValue(tempMessageList.Last());
            connection.Unlock();
            return returnValue;
        }
Ejemplo n.º 3
0
 private static int rename_file(IFTPConnection connection, string fromRemoteFileName, string toRemoteFileName)
 {
     connection.Lock();
     int returnValue = 0;
     string[] tempMessageList = connection.SendCommand("RNFR " + fromRemoteFileName);
     var currentMsg = tempMessageList.Last();
     returnValue = FTPUtilities.GetMessageReturnValue(currentMsg);
     if (returnValue == 350)
     {
         tempMessageList = connection.SendCommand("RNTO " + toRemoteFileName);
         returnValue = FTPUtilities.GetMessageReturnValue(currentMsg);
     }
     connection.Unlock();
     return returnValue;
 }
Ejemplo n.º 4
0
 public int SetCurrentDirectory(IFTPConnection connection, string remotePath)
 {
     if(_cwdIsDirty)
         CurrentDirectory = GetCurrentDirectory(connection);
     if (remotePath.SameAsCurrentFTPDirectory(CurrentDirectory) && remotePath != MOVEUPDIR) return 220;
     connection.Lock();
     int returnValue = 0;
     string[] tempMessageList = set_directory(connection, remotePath);
     returnValue = FTPUtilities.GetMessageReturnValue(tempMessageList.Last());
     connection.Unlock();
     CurrentDirectory = GetCurrentDirectory(connection);
     return returnValue;
 }
Ejemplo n.º 5
0
 public void MoveUp(IFTPConnection connection)
 {
     _cwdIsDirty = true;
     connection.Lock();
     connection.SendCommand("CWD " + MOVEUPDIR);
     connection.Unlock();
 }
Ejemplo n.º 6
0
 private static int set_mode(IFTPConnection conn, string mode)
 {
     conn.Lock();
     int returnValue = 0;
     string[] tempMessageList = conn.SendCommand(mode);
     returnValue = FTPUtilities.GetMessageReturnValue((string)tempMessageList.Last());
     conn.Unlock();
     return returnValue;
 }
Ejemplo n.º 7
0
        private static void set_data_port(IFTPConnection conn, int portNumber)
        {
            conn.Lock();

            int returnValue = 0;
            int portHigh = portNumber >> 8;
            int portLow = portNumber & 255;

            string[] tempMessageList = conn.SendCommand("PORT "
                                                        + FTPUtilities.GetLocalAddressList()[0].ToString().Replace(".", ",")
                                                        + "," + portHigh.ToString() + "," + portLow);

            returnValue = FTPUtilities.GetMessageReturnValue((string)tempMessageList.Last());
            if (returnValue != 200)
            {
                throw new Exception((string)tempMessageList.Last());
            }
            conn.Lock();
        }
Ejemplo n.º 8
0
 private static int get_port_number(IFTPConnection conn)
 {
     int port = 0;
     conn.Lock();
     switch (conn.Mode)
     {
         case FTPMode.Active:
             var rnd = new Random((int)DateTime.Now.Ticks);
             port = DATA_PORT_RANGE_FROM + rnd.Next(DATA_PORT_RANGE_TO - DATA_PORT_RANGE_FROM);
             break;
         case FTPMode.Passive:
             int returnValue = 0;
             string[] tempMessageList = conn.SendCommand("PASV");
             returnValue = FTPUtilities.GetMessageReturnValue(tempMessageList.Last());
             if (returnValue != 227)
             {
                 if (tempMessageList.Last().Length > 4)
                 {
                     throw new Exception(tempMessageList.Last());
                 }
                 throw new Exception(tempMessageList.Last() + " Passive Mode not implemented");
             }
             var message = tempMessageList.Last();
             int index1 = message.IndexOf(",", 0);
             int index2 = message.IndexOf(",", index1 + 1);
             int index3 = message.IndexOf(",", index2 + 1);
             int index4 = message.IndexOf(",", index3 + 1);
             int index5 = message.IndexOf(",", index4 + 1);
             int index6 = message.IndexOf(")", index5 + 1);
             port = 256 * int.Parse(message.Substring(index4 + 1, index5 - index4 - 1)) + int.Parse(message.Substring(index5 + 1, index6 - index5 - 1));
             break;
     }
     conn.Unlock();
     return port;
 }