Exemplo n.º 1
0
        public Mp3File UploadNewFile(string input, DateTime date, string titel, CategoryObj cat)
        {
            string filename = string.Format("{0}-{1}.mp3", date.ToString("yyyyMMdd"), titel.Replace(" ", "_").Replace(".", "").ToLowerInvariant());
            string targetfilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), filename);

            EncodeMP3(input, targetfilename);

            FtpClient c = new FtpClient(FTPServer, FTPServerUser, FTPServerPassw);
            bool result = c.UploadFile(targetfilename, string.Format("public_html/{0}/{1}", GetFTPServerLocation(cat), filename));
            if (!result)
                throw new ApplicationException("Uploaden niet gelukt");

            Mp3File mp3 = new Mp3File();
            mp3.naam = filename;
            mp3.size = new FileInfo(targetfilename).Length;
            mp3.url = string.Format("{0}{1}/{2}", BaseWebUrl, GetFTPServerLocation(cat), filename);

            File.Delete(targetfilename);

            return mp3;
        }
Exemplo n.º 2
0
        public List<Mp3File> GetLastFiles(int top)
        {
            FtpClient c = new FtpClient(FTPServer, FTPServerUser, FTPServerPassw);
            //bool result = c.UploadFile(targetFilename, string.Format("{0}{1}", Config.FTPServerLocation, new FileInfo(targetFilename).Name));

            //List<string> files = new List<string>();

            //files.Sort();

            List<Mp3File> mp3s = new List<Mp3File>();
            foreach (string dir in FTPServerLocation)
            {
                List<string> files = c.GetDirectoryList(dir);
                files.Remove(".");
                files.Remove("..");
                files.Sort();
                //foreach (string f in )
                //    if (!f.Equals(".") && !f.Equals(".."))
                //        files.Add(dir + "/" + f);

                string dirname = dir.Replace("public_html/", "");

                for (int i = 0; i < 10; i++)
                {
                    string filename = files[files.Count - (i + 1)];

                    Mp3File mp3 = new Mp3File();
                    mp3.url = "http://www.example.com/" + dirname + "/" + filename;
                    mp3.size = c.GetFileSize(dir + "/" + filename);
                    mp3.naam = dirname + " - " + filename;

                    mp3s.Add(mp3);
                }
            }

            return mp3s;
        }