示例#1
0
        private void cmd_stor_real(string cmd, string p1, bool isappend)
        {
            bool flag = false;
            int  max  = 10000;

            byte[] bf = new byte[max];
            if (p1.Length == 0)
            {
                this.send("500 file name not specified\r\n");
            }
            else
            {
                string       str = this.apply_path(p1);
                string       reason;
                SimpleStream simpleStream = this.files.open(str, false, isappend, out reason);
                if (simpleStream == null)
                {
                    this.send("550 store: open failed {0} {1} mode={2}\r\n", (object)str, (object)reason, isappend ? (object)"Append" : (object)"Write");
                }
                else
                {
                    Ftplink dataLink = this.get_data_link();
                    if (dataLink == null)
                    {
                        return;
                    }
                    if (this.restart != 0L)
                    {
                        simpleStream.seek(this.restart);
                    }
                    this.restart = 0L;
                    int sz;
                    do
                    {
                        sz = dataLink.read_bytes(bf, max, 30000, out bool _, out reason);
                        if (sz <= 0)
                        {
                            goto label_11;
                        }
                    }while (simpleStream.write(bf, 0, sz) == sz);
                    flag = true;
label_11:
                    dataLink.netclose();
                    simpleStream.close();
                    if (flag)
                    {
                        this.send("550 Failed writing data\r\n");
                    }
                    else
                    {
                        this.send("226 Transfer complete {0} stored {1}\r\n", (object)str, isappend ? (object)"Append" : (object)"Write");
                        if (this.files.get_run().Length <= 0)
                        {
                            return;
                        }
                        MyMain.spawn(this.files.get_run(), this.files.apply_profile(str));
                    }
                }
            }
        }
示例#2
0
        public SimpleStream open_raw(
            string fname,
            bool isread,
            bool isappend,
            out string reason)
        {
            reason = "";
            bool   isreadonly;
            string fname1 = this.apply_profile(fname, out isreadonly);

            if (isreadonly && !isread)
            {
                reason = "Readonly directory";
                return((SimpleStream)null);
            }
            SimpleStream simpleStream = new SimpleStream();

            clib.imsg("ss.open {0} ", (object)fname1);
            if (!simpleStream.open(fname1, isread, isappend, this.current_user, out reason))
            {
                return((SimpleStream)null);
            }
            clib.imsg("ss.open WORKED {0} ", (object)fname1);
            return(simpleStream);
        }
示例#3
0
 private static bool send_file_headers(Websvc w, SimpleStream ss)
 {
     w.chan.write(string.Format("Date: {0}\r\n", (object)ss.lastmodified().ToHttpDate()));
     w.chan.write(string.Format("ETag: {0}\r\n", (object)ss.etag()));
     w.chan.write(string.Format("Last-Modified: {0}\r\n", (object)ss.lastmodified().ToHttpDate()));
     return(true);
 }
示例#4
0
        public static bool send_file(Websvc w, string fname, bool attached)
        {
            SimpleStream ss = new SimpleStream();

            ss.open(fname, true, false, out string _);
            return(WebFile.send_file(w, ss, fname, attached, true));
        }
示例#5
0
        private void cmd_retr(string cmd, string p1)
        {
            bool flag = false;
            int  sz   = 10000;

            byte[] bf = new byte[sz];
            if (p1.Length == 0)
            {
                this.send("500 file name not specified\r\n");
            }
            else
            {
                string       fname = this.apply_path(p1);
                string       reason;
                SimpleStream simpleStream = this.files.open(fname, true, false, out reason);
                if (simpleStream == null)
                {
                    this.send("550 Could not open  {0} {1}\r\n", (object)fname, (object)reason);
                }
                else
                {
                    Ftplink dataLink = this.get_data_link();
                    if (dataLink == null)
                    {
                        return;
                    }
                    if (this.restart != 0L)
                    {
                        simpleStream.seek(this.restart);
                    }
                    this.restart = 0L;
                    int len;
                    do
                    {
                        len = simpleStream.read(bf, 0, sz);
                        if (len <= 0)
                        {
                            goto label_11;
                        }
                    }while (dataLink.write(bf, len));
                    this.imsg("Write failed sending data");
                    flag = true;
label_11:
                    dataLink.netclose();
                    simpleStream.close();
                    if (flag)
                    {
                        this.send("550 Failed writing data {0}\r\n", (object)fname);
                    }
                    else
                    {
                        this.send("226 Transfer complete {0}\r\n", (object)fname);
                    }
                }
            }
        }
示例#6
0
 public static bool send_file(
     Websvc w,
     SimpleStream ss,
     string fname,
     bool attached,
     bool andbody)
 {
     if (ss == null || !ss.isopen)
     {
         string x = "Send:File not found " + fname;
         w.chan.write(string.Format("HTTP/1.1 500 FILE NOT FOUND\r\nContent-Length: {0}\r\n\r\n", (object)x.Length));
         w.chan.write(x);
         return(false);
     }
     if (!andbody)
     {
         Web.any_header(w, clib.content_type(fname), "200 Ok", 0, false);
         WebFile.send_file_headers(w, ss);
         w.body_send();
         return(true);
     }
     if (w.ifmodified == ss.lastmodified().ToHttpDate())
     {
         Web.any_header(w, clib.content_type(fname), "304 Not modified", 0, false);
         w.body_send();
         return(true);
     }
     Web.any_header(w, clib.content_type(fname), "200 Ok", -1, true);
     WebFile.send_file_headers(w, ss);
     if (attached)
     {
         w.chan.write(string.Format("Content-Disposition: attachment; filename=\"{0}\"\r\n", (object)clib.fileonly(fname)));
     }
     w.chan.write("\r\n");
     while (true)
     {
         int    sz       = 10000;
         byte[] numArray = new byte[sz];
         int    count    = ss.read(numArray, 0, sz);
         if (count > 0)
         {
             w.chan.write(string.Format("{0:x}\r\n", (object)count));
             w.chan.Write(numArray, 0, count);
             w.chan.write("\r\n");
         }
         else
         {
             break;
         }
     }
     w.chan.write("0\r\n\r\n");
     return(true);
 }