Exemplo n.º 1
0
        private Ftplink get_data_link()
        {
            Ftplink ftplink = new Ftplink();

            this.imsg("get_data_link: ssl_data={0}", (object)this.ssl_data);
            if (this.listen != null)
            {
                this.send("150 listening for {0} connection {1} (passive)\r\n", this.isbin ? (object)"BINARY" : (object)"ASCII", this.ssl_data ? (object)"SSL" : (object)"NoSSL");
                ftplink.accept(this.listen, 30);
                this.listen = (TcpListener)null;
                if (this.ssl_data)
                {
                    ftplink.ssl_enable(this.port_ip, true);
                }
            }
            else
            {
                this.send("150 Opening {0} mode connection {1} {2} (active)\r\n", this.isbin ? (object)"BINARY" : (object)"ASCII", (object)this.port_ip, (object)this.port_port);
                string reason;
                if (!ftplink.open(this.port_ip, this.port_port, out reason))
                {
                    clib.imsg("fl.open failed to connect {0}", (object)reason);
                    this.send("500 Cannot connect to {0} {1}\r\n", (object)this.port_ip, (object)this.port_port);
                    return((Ftplink)null);
                }
                clib.imsg("fl.open worked, connected ok ");
                if (this.ssl_data)
                {
                    ftplink.ssl_enable(this.port_ip, true);
                }
            }
            return(ftplink);
        }
Exemplo n.º 2
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));
                    }
                }
            }
        }
Exemplo n.º 3
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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void cmd_list(string cmd, string p1)
        {
            string  path     = this.apply_path(p1);
            Ftplink dataLink = this.get_data_link();

            if (dataLink == null)
            {
                return;
            }
            foreach (Fileinfo fileinfo in this.files.get_index(path))
            {
                dataLink.send(string.Format("{0}rwxrwxrwx   1 user     user     {1,-10} {2} {3}\r\n", fileinfo.isdir ? (object)"d" : (object)"-", (object)fileinfo.size, (object)this.list_date(fileinfo.modified), (object)clib.string_to_utf8(clib.fileonly(fileinfo.name))));
            }
            dataLink.netclose();
            this.send("226 Transfer complete for path {0}\r\n", (object)path);
        }
Exemplo n.º 5
0
        private void cmd_mlsd(string cmd, string p1)
        {
            string  path     = this.apply_path(p1);
            Ftplink dataLink = this.get_data_link();

            if (dataLink == null)
            {
                return;
            }
            foreach (Fileinfo f in this.files.get_index(path))
            {
                dataLink.netprintf("{0}\r\n", (object)this.fact_get(f));
            }
            dataLink.netclose();
            this.send("226 Transfer complete for path {0}\r\n", (object)path);
        }
Exemplo n.º 6
0
        private void cmd_nlst(string cmd, string p1)
        {
            Ftplink dataLink = this.get_data_link();

            if (dataLink == null)
            {
                return;
            }
            string path = this.apply_path(p1);

            foreach (Fileinfo fileinfo in this.files.get_index_fast(path))
            {
                dataLink.netprintf("{0}\r\n", (object)clib.string_to_utf8(clib.fileonly(fileinfo.name, this.cwd)));
            }
            dataLink.netclose();
            this.send("226 Transfer complete for path {0}\r\n", (object)path);
        }