Exemplo n.º 1
0
 public void UploadFileFtp(Data file, string folder)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a data structure from the file path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <returns>
        /// The data structure.
        /// </returns>
        /// <exception cref="System.ArgumentException">Path is a required parameter.</exception>
        public static Data CreateFromFilePath(string path, string mimeType)
        {
            if (path == null)
            {
                throw new ArgumentException("Path is a required parameter.", "path");
            }

            Data data = new Data
            {
                Type = mimeType,
                Name = Path.GetFileName(path),
                Bits = File.ReadAllBytes(path)
            };

            return data;
        }
Exemplo n.º 3
0
        public void UploadFileFtp(Data file, string folder)
        {
            var tryAgain = true;
            while (tryAgain)
            {
                var request = (FtpWebRequest)WebRequest.Create("ftp://" + _ftpConfiguration.Url + "/" + folder + "/" + Path.GetFileName(file.Name));
                try
                {
                    request.Method = WebRequestMethods.Ftp.UploadFile;
                    request.Credentials = new NetworkCredential(_ftpConfiguration.UserName, _ftpConfiguration.Password);
                    request.UsePassive = true;
                    request.UseBinary = true;
                    request.KeepAlive = false;
                    request.ServicePoint.Expect100Continue = false;
                    //request.Timeout = 1000000;

                    using (Stream reqStream = request.GetRequestStream())
                    {
                        //reqStream.ReadTimeout = 3000000;
                        //reqStream.WriteTimeout = 3000000;
                        reqStream.Write(file.Bits, 0, file.Bits.Length);
                        reqStream.Flush();
                        reqStream.Close();
                    }
                    tryAgain = false;
                }
                catch (Exception exception)
                {
                    Logger.LogExceptions(exception);
                    if (exception.Message.Contains("Not logged in"))
                    {
                        break;
                    }
                }
                finally
                {
                    request.Abort();
                    request = null;
                    GC.Collect();
                }

            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the data structure from the URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="mimeType">Type of the MIME. If <c>null</c> the ContentType header of the url will be used.</param>
        /// <returns>
        /// The data structure.
        /// </returns>
        /// <exception cref="System.ArgumentException">Url is a required parameter.</exception>
        public static Data CreateFromUrl(string url, string mimeType = null)
        {
            if (url == null)
            {
                throw new ArgumentException("Url is a required parameter.", "url");
            }

            var bytes = new byte[0];

            using (WebClient wc = new WebClient())
            {
                Data data = new Data();
                data.Bits = wc.DownloadData(url);
                data.Name = Path.GetFileName(url);

                if (mimeType != null)
                {
                    data.Type = mimeType;
                }
                else
                {
                    data.Type = wc.ResponseHeaders["content-type"];
                }

                return data;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Upload a file
 /// </summary>
 /// <param name="upload">Upload data</param>
 /// <returns></returns>
 public UploadResult UploadFile(Data upload)
 {
     return WordPressService.UploadFile(WordPressSiteConfig.BlogId, WordPressSiteConfig.Username, WordPressSiteConfig.Password, upload);
 }