예제 #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 (!Authenticated)
            {
                Socket.WriteLine("530 Please authenticate firtst !");
                return;
            }

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

            if (!eArgs.Validated)
            {
                Socket.WriteLine("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(Encoding.Default.GetBytes(dr["Name"] + "\r\n"));
                }
                socket.Send(Encoding.Default.GetBytes("aaa\r\n"));

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

                Socket.WriteLine("226 Transfer Complete.");
            }
            catch
            {
                Socket.WriteLine("426 Connection closed; transfer aborted.");
            }
        }
예제 #2
0
        internal FileSysEntry_EventArgs OnGetDirInfo(FTP_Session session, string dir)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, dir, "");

            if (GetDirInfo != null)
            {
                GetDirInfo(this, oArg);
            }
            return(oArg);
        }
예제 #3
0
        internal bool OnDeleteFile(FTP_Session session, string file)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");

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

            return(oArg.Validated);
        }
예제 #4
0
        internal Stream OnStoreFile(FTP_Session session, string file)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");

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

            return(oArg.FileStream);
        }
예제 #5
0
        internal bool OnRenameDirFile(FTP_Session session, string from, string to)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, from, to);

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

            return(oArg.Validated);
        }
예제 #6
0
        internal bool OnDeleteDir(FTP_Session session, string dir)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, dir, "");

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

            return(oArg.Validated);
        }
예제 #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 (FileExists != null)
            {
                FileExists(this, oArg);
            }

            return(oArg.Validated);
        }
예제 #8
0
        internal bool OnDeleteFile(FTP_Session session, string file)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");
            if (DeleteFile != null)
            {
                DeleteFile(this, oArg);
            }

            return oArg.Validated;
        }
예제 #9
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 (!Authenticated)
            {
                Socket.WriteLine("530 Please authenticate firtst !");
                return;
            }

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

            if (!eArgs.Validated)
            {
                Socket.WriteLine("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(Encoding.Default.GetBytes(date + " <DIR> " + name + "\r\n"));
                    }
                    else
                    {
                        socket.Send(Encoding.Default.GetBytes(date + " " + dr["Size"] + " " + name + "\r\n"));
                    }
                }

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

                Socket.WriteLine("226 Transfer Complete.");
            }
            catch
            {
                Socket.WriteLine("426 Connection closed; transfer aborted.");
            }
        }
예제 #10
0
        internal Stream OnStoreFile(FTP_Session session, string file)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, file, "");
            if (StoreFile != null)
            {
                StoreFile(this, oArg);
            }

            return oArg.FileStream;
        }
예제 #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 (FileExists != null)
            {
                FileExists(this, oArg);
            }

            return oArg.Validated;
        }
예제 #12
0
        internal bool OnRenameDirFile(FTP_Session session, string from, string to)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, from, to);
            if (RenameDirFile != null)
            {
                RenameDirFile(this, oArg);
            }

            return oArg.Validated;
        }
예제 #13
0
        internal bool OnDeleteDir(FTP_Session session, string dir)
        {
            FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, dir, "");
            if (DeleteDir != null)
            {
                DeleteDir(this, oArg);
            }

            return oArg.Validated;
        }
예제 #14
0
 internal FileSysEntry_EventArgs OnGetDirInfo(FTP_Session session, string dir)
 {
     FileSysEntry_EventArgs oArg = new FileSysEntry_EventArgs(session, dir, "");
     if (GetDirInfo != null)
     {
         GetDirInfo(this, oArg);
     }
     return oArg;
 }