Example #1
0
        /// <summary>
        /// 将http转成ftp
        /// </summary>
        /// <param name="httpUrl"></param>
        /// <returns></returns>
        public string ReplaceProtocolHttp2Ftp(string httpUrl)
        {
            string ftpUri;

            if (string.IsNullOrEmpty(httpUrl))
            {
                ftpUri = FtpUrl;
            }
            else if (httpUrl.StartsWith(ReadUrl))
            {
                ftpUri = string.Format("{0}{1}", FtpUrl, httpUrl.Replace(ReadUrl, ""));
            }
            else if (httpUrl.StartsWith(RootPath))
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl.Replace("/" + RootPath, ""), httpUrl);
            }
            else if (httpUrl.StartsWith(string.Format("ftp://{0}", Server)))
            {
                ftpUri = httpUrl;
            }
            else if (httpUrl.StartsWith(FtpUrl))
            {
                ftpUri = httpUrl;
            }
            else if (httpUrl.StartsWith(string.Format("/{0}", RootPath)))
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl.Replace("/" + RootPath, ""), httpUrl);
            }
            else
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl, httpUrl);
            }

            return(ftpUri);
        }
Example #2
0
        private WebRequest GetRequest(string path, string method, bool useBinary = false, long contentLength = 0)
        {
            string ftpUri;

            if (!string.IsNullOrEmpty(path) && path.StartsWith("/"))
            {
                path = path.Substring(1);
            }
            if (string.IsNullOrEmpty(path))
            {
                ftpUri = FtpUrl;
            }
            else if (path.StartsWith(RootPath))
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl.Replace("/" + RootPath, ""), path);
            }
            else if (path.StartsWith(string.Format("ftp://{0}", Server)))
            {
                ftpUri = path;
            }
            else
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl, path);
            }
            var ftp = (FtpWebRequest)WebRequest.Create(new Uri(ftpUri));

            ftp.Credentials   = new NetworkCredential(User, Password);
            ftp.Method        = method;
            ftp.UseBinary     = useBinary;
            ftp.ContentLength = contentLength;
            return(ftp);
        }
Example #3
0
        /// <summary>
        /// 创建目录
        /// </summary>
        /// <param name="path"></param>
        public void CreateDirectory(string path)
        {
            var    parts = FtpPathUtil.SplitPaths(path);
            string url   = string.Empty;

            parts.ForEach(part =>
            {
                url = FtpPathUtil.Combine(url, part);
                if (!IsDirectoryExist(url))
                {
                    CreateChildDirectory(url);
                }
            });
        }
Example #4
0
        private WebResponse SendRequest(string path, string method, bool useBinary = false, long contentLength = 0)
        {
            LoggerFactory.Instance.Info(path);
            string ftpUri;

            if (string.IsNullOrEmpty(path))
            {
                ftpUri = FtpUrl;
            }
            else if (path.StartsWith(ReadUrl))
            {
                ftpUri = string.Format("{0}{1}", FtpUrl, path.Replace(ReadUrl, ""));
            }
            else if (path.StartsWith(RootPath) && !string.IsNullOrEmpty(RootPath))
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl.Replace("/" + RootPath, ""), path);
            }
            else if (path.StartsWith(string.Format("ftp://{0}", Server)))
            {
                ftpUri = path;
            }
            else if (path.StartsWith(FtpUrl))
            {
                ftpUri = path;
            }
            else if (path.StartsWith(string.Format("/{0}", RootPath)))
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl.Replace("/" + RootPath, ""), path);
            }
            else
            {
                ftpUri = FtpPathUtil.Combine(FtpUrl, path);
            }

            LoggerFactory.Instance.Info(ftpUri);
            var ftp = (FtpWebRequest)WebRequest.Create(new Uri(ftpUri));

            ftp.Credentials   = new NetworkCredential(User, Password);
            ftp.Method        = method;
            ftp.UseBinary     = useBinary;
            ftp.ContentLength = contentLength;
            return(ftp.GetResponse());
        }