示例#1
0
        /// <summary>
        /// 将数据转换为文件上传至FTP服务器
        /// </summary>
        /// <param name="Info"></param>
        /// <param name="ActionName"></param>
        /// <returns>返回文件所在地址</returns>
        public string UpLoadData(T Info, List <string> ActionName, out string outFileName, string InFileName = null)
        {
            string resultUri = string.Empty;
            //生成文件名
            var FileName = InFileName == null?DateTime.Now.Ticks.ToString() + ".txt" : InFileName;

            //文件完整目录
            var ParhAndFileName = Path + "\\" + FileName;
            //创建工具实体
            var fileTool = new FileTool(Path);

            //创建工具
            fileTool.CreateFile(Path, FileName);
            //数据序列化
            var DataStr = JsonConvert.SerializeObject(Info);
            //写文件
            var result = fileTool.AppendNewFile(DataStr);

            if (result == "success")
            {
                //生成上传路径
                List <string> UpLoadPaths = ActionName;
                UpLoadPaths.Add(DateTime.Now.ToString("yyyyMMdd"));
                //上传文件
                var IsSuccess = FTPHelp.FtpUploadFile(ParhAndFileName, FTPInfo, UpLoadPaths, out resultUri);
                //上传成功,删除临时文件
                if (IsSuccess)
                {
                    fileTool.DeleteFile(ParhAndFileName);
                }
            }
            outFileName = FileName;
            return(resultUri);
        }
示例#2
0
        /// <summary>
        /// 从FTP下载文件,并转换为实体类
        /// </summary>
        /// <param name="FTPUri"></param>
        /// <returns></returns>
        public T DownloadToData(string FTPUri)
        {
            //生成文件名
            var FileName = DateTime.Now.Ticks.ToString() + ".txt";
            //创建工具实体
            var fileTool = new FileTool(Path);
            //文件完整目录
            var ParhAndFileName = Path + "\\" + FileName;
            //下载失败则返回空
            var IsSuccess = FTPHelp.FtpDownload(FTPUri, ParhAndFileName, FTPInfo, true, false);

            if (IsSuccess)
            {
                //读取文件内容
                var DataStr = fileTool.GetFileContent(Path, FileName);
                if (DataStr != null && DataStr != string.Empty)
                {
                    T result = JsonConvert.DeserializeObject <T>(DataStr);
                    fileTool.DeleteFile(ParhAndFileName);
                    return(result);
                }
            }
            return(Activator.CreateInstance <T>());
        }
示例#3
0
        /// <summary>
        /// 上传文件至FTP服务器
        /// </summary>
        /// <param name="FilePath">文件详细目录</param>
        /// <param name="uri">上传地址</param>
        /// <returns></returns>

        public bool UpFile(string FilePath, string uri)
        {
            string FileUri = string.Empty;

            return(FTPHelp.FtpUploadFile(new FileInfo(FilePath), FTPInfo.FTPUserName, FTPInfo.FTPUserPwd, uri, out FileUri));
        }
示例#4
0
 /// <summary>
 /// 删除FTP上的文件
 /// </summary>
 /// <param name="uri"></param>
 /// <returns></returns>
 public bool FileDelete(string uri)
 {
     return(FTPHelp.FileDelete(uri, FTPInfo));
 }
示例#5
0
 /// <summary>
 /// FTP文件重命名
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="NewFileName"></param>
 /// <returns></returns>
 public bool FileRename(string uri, string NewFileName)
 {
     return(FTPHelp.FileRename(uri, FTPInfo.FTPUserName, FTPInfo.FTPUserPwd, NewFileName));
 }
示例#6
0
 /// <summary>
 /// FTP创建文件夹
 /// </summary>
 /// <param name="uri"></param>
 /// <returns></returns>
 public bool MakeDir(string uri)
 {
     return(FTPHelp.MakeDir(uri, FTPInfo));
 }
示例#7
0
 /// <summary>
 /// 下载文件至指定路径
 /// </summary>
 /// <param name="DownPath">下载路径</param>
 /// <param name="uri">下载地址</param>
 /// <returns></returns>
 public bool DownloadFile(string DownPath, string uri)
 {
     return(FTPHelp.FtpDownload(uri, DownPath, FTPInfo));
 }