Ejemplo n.º 1
0
        private void NLST(string argsText)
        {
            /*
             *      This command causes a directory listing to be sent from
             *      server to user site.  The pathname should specify a
             *      directory or other system-specific file group descriptor; a
             *      null argument implies the current directory.  The server
             *      will return a stream of names of files and no other
             *      information.  The data will be transferred in ASCII or
             *      EBCDIC type over the data connection as valid pathname
             *      strings separated by <CRLF> or <NL>.  (Again the user must
             *      ensure that the TYPE is correct.)  This command is intended
             *      to return information that can be used by a program to
             *      further process the files automatically.  For example, in
             *      the implementation of a "multiple get" function.
             */
            if (!m_Authenticated)
            {
                m_pSocket.SendLine("530 Please authenticate firtst !");
                return;
            }

            //---- See if path accessible
            FileSysEntry_EventArgs eArgs = m_pServer.OnGetDirInfo(this, GetAndNormailizePath(argsText));

            if (!eArgs.Validated)
            {
                m_pSocket.SendLine("550 Access denied or directory dosen't exist !");
                return;
            }
            DataSet ds = eArgs.DirInfo;

            Socket socket = GetDataConnection();

            if (socket == null)
            {
                return;
            }

            try{
                //		string dir = GetAndNormailizePath(argsText);
                //		DataSet ds = m_pServer.OnGetDirInfo(dir);

                foreach (DataRow dr in ds.Tables["DirInfo"].Rows)
                {
                    socket.Send(System.Text.Encoding.Default.GetBytes(dr["Name"].ToString() + "\r\n"));
                }
                socket.Send(System.Text.Encoding.Default.GetBytes("aaa\r\n"));

                socket.Shutdown(SocketShutdown.Both);
                socket.Close();

                m_pSocket.SendLine("226 Transfer Complete.");
            }
            catch {
                m_pSocket.SendLine("426 Connection closed; transfer aborted.");
            }
        }
Ejemplo n.º 2
0
        internal FileSysEntry_EventArgs OnGetDirInfo(FTP_Session session, string dir)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, dir, "");

            if (this.GetDirInfo != null)
            {
                this.GetDirInfo(this, oArg);
            }
            return(oArg);
        }
Ejemplo n.º 3
0
        internal bool OnDeleteFile(FTP_Session session, string file)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");

            if (this.DeleteFile != null)
            {
                this.DeleteFile(this, oArg);
            }

            return(oArg.Validated);
        }
Ejemplo n.º 4
0
        internal Stream OnStoreFile(FTP_Session session, string file)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");

            if (this.StoreFile != null)
            {
                this.StoreFile(this, oArg);
            }

            return(oArg.FileStream);
        }
Ejemplo n.º 5
0
        internal bool OnRenameDirFile(FTP_Session session, string from, string to)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, from, to);

            if (this.RenameDirFile != null)
            {
                this.RenameDirFile(this, oArg);
            }

            return(oArg.Validated);
        }
Ejemplo n.º 6
0
        internal bool OnDeleteDir(FTP_Session session, string dir)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, dir, "");

            if (this.DeleteDir != null)
            {
                this.DeleteDir(this, oArg);
            }

            return(oArg.Validated);
        }
Ejemplo n.º 7
0
        internal bool OnFileExists(FTP_Session session, string file)
        {
            // Remove last /
            file = file.Substring(0, file.Length - 1);

            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");

            if (this.FileExists != null)
            {
                this.FileExists(this, oArg);
            }

            return(oArg.Validated);
        }
Ejemplo n.º 8
0
        private void LIST(string argsText)
        {
            /*
             *      This command causes a list to be sent from the server to the
             *      passive DTP.  If the pathname specifies a directory or other
             *      group of files, the server should transfer a list of files
             *      in the specified directory.  If the pathname specifies a
             *      file then the server should send current information on the
             *      file.  A null argument implies the user's current working or
             *      default directory.  The data transfer is over the data
             *      connection in type ASCII or type EBCDIC.  (The user must
             *      ensure that the TYPE is appropriately ASCII or EBCDIC).
             *      Since the information on a file may vary widely from system
             *      to system, this information may be hard to use automatically
             *      in a program, but may be quite useful to a human user.
             */
            if (!m_Authenticated)
            {
                m_pSocket.SendLine("530 Please authenticate firtst !");
                return;
            }

            // ToDo: custom errors
            //---- See if path accessible
            FileSysEntry_EventArgs eArgs = m_pServer.OnGetDirInfo(this, GetAndNormailizePath(argsText));

            if (!eArgs.Validated)
            {
                m_pSocket.SendLine("550 Access denied or directory dosen't exist !");
                return;
            }
            DataSet ds = eArgs.DirInfo;

            Socket socket = GetDataConnection();

            if (socket == null)
            {
                return;
            }

            try{
                //	string dir = GetAndNormailizePath(argsText);
                //	DataSet ds = m_pServer.OnGetDirInfo(dir);

                foreach (DataRow dr in ds.Tables["DirInfo"].Rows)
                {
                    string name  = dr["Name"].ToString();
                    string date  = Convert.ToDateTime(dr["Date"]).ToString("MM-dd-yy hh:mmtt");
                    bool   isDir = Convert.ToBoolean(dr["IsDirectory"]);

                    if (isDir)
                    {
                        socket.Send(System.Text.Encoding.Default.GetBytes(date + " <DIR> " + name + "\r\n"));
                    }
                    else
                    {
                        socket.Send(System.Text.Encoding.Default.GetBytes(date + " " + dr["Size"].ToString() + " " + name + "\r\n"));
                    }
                }

                socket.Shutdown(SocketShutdown.Both);
                socket.Close();

                m_pSocket.SendLine("226 Transfer Complete.");
            }
            catch {
                m_pSocket.SendLine("426 Connection closed; transfer aborted.");
            }
        }
Ejemplo n.º 9
0
		internal bool OnDeleteFile(FTP_Session session,string file)
		{
			FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session,file,"");
			if(this.DeleteFile != null){
				this.DeleteFile(this,oArg);
			}
			
			return oArg.Validated;
		}
Ejemplo n.º 10
0
		internal Stream OnStoreFile(FTP_Session session,string file)
		{
			FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session,file,"");
			if(this.StoreFile != null){
				this.StoreFile(this,oArg);
			}
			
			return oArg.FileStream;
		}
Ejemplo n.º 11
0
		internal bool OnFileExists(FTP_Session session,string file)
		{
			// Remove last /
			file = file.Substring(0,file.Length - 1);

			FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session,file,"");
			if(this.FileExists != null){
				this.FileExists(this,oArg);
			}
			
			return oArg.Validated;
		}
Ejemplo n.º 12
0
		internal bool OnRenameDirFile(FTP_Session session,string from,string to)
		{
			FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session,from,to);
			if(this.RenameDirFile != null){
				this.RenameDirFile(this,oArg);
			}
			
			return oArg.Validated;
		}
Ejemplo n.º 13
0
		internal bool OnDeleteDir(FTP_Session session,string dir)
		{
			FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session,dir,"");
			if(this.DeleteDir != null){
				this.DeleteDir(this,oArg);
			}
			
			return oArg.Validated;
		}
Ejemplo n.º 14
0
		internal FileSysEntry_EventArgs OnGetDirInfo(FTP_Session session,string dir)
		{
			FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session,dir,"");
			if(this.GetDirInfo != null){
				this.GetDirInfo(this,oArg);
			}
			return oArg;
		}