Beispiel #1
0
 /// <summary>
 /// 移动目录
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="fileName"></param>
 /// <param name="DirectoryName"></param>
 /// <returns></returns>
 public bool MoveFile(string filePath, string fileName, string DirectoryName)
 {
     try
     {
         var dbNameTxt = _errorAddress + @"\Move" + DateTime.Now.ToLongDateString() + ".txt";
         var ftpUei    = new Uri(_ftpServerIp + filePath);
         var cf        = new clsFTP(ftpUei, _ftpUserID, _ftpPassword);
         var b         = cf.MoveFileToAnotherDirectory(fileName, DirectoryName);
         if (b)
         {
             var stream = new StreamWriter(dbNameTxt, true);
             stream.WriteLine("移动文件成功。文件名为:" + fileName + "时间:)" + DateTime.Now.ToString(CultureInfo.InvariantCulture));
             stream.Close();
             return(true);
         }
         else
         {
             var strea = new StreamWriter(dbNameTxt, true);
             strea.WriteLine("移动文件失败。错误信息为" + cf.ErrorMsg + " 文件名为:" + fileName + "时间:)" + DateTime.Now.ToString(CultureInfo.InvariantCulture));
             strea.Close();
             return(false);
         }
     }
     catch (Exception ex)
     {
         var dbNameTxt = _errorAddress + @"\ErrorMovee" + DateTime.Now.ToLongDateString() + ".txt";
         var stream    = new StreamWriter(dbNameTxt, true);
         stream.WriteLine("移动文件失败。错误为:" + ex.Message + ";文件名为:" + fileName + "时间:)" + DateTime.Now.ToString(CultureInfo.InvariantCulture));
         stream.Close();
         return(false);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public bool DeleteFileName(string filePath, string fileName)
 {
     try
     {
         string       dbNameTxt = _errorAddress + @"\Delete" + DateTime.Now.ToLongDateString() + ".txt";
         StreamWriter Stream;
         Uri          FtpUEI = new Uri(_ftpServerIp + filePath);
         clsFTP       cf     = new clsFTP(FtpUEI, _ftpUserID, _ftpPassword);
         bool         b      = cf.DeleteFile(fileName);
         if (b)
         {
             Stream = new StreamWriter(dbNameTxt, true);
             Stream.WriteLine("删除文件成功。文件名为:" + fileName + "时间:)" + DateTime.Now.ToString());
             Stream.Close();
             return(true);
         }
         else
         {
             string       dbxt  = _errorAddress + @"\ErrorDelete" + DateTime.Now.ToLongDateString() + ".txt";
             StreamWriter Strea = new StreamWriter(dbxt, true);
             Strea.WriteLine("删除文件失败。错误信息为" + cf.ErrorMsg + " 文件名为:" + fileName + "时间:)" + DateTime.Now.ToString());
             Strea.Close();
             return(false);
         }
     }
     catch (Exception ex)
     {
         string       dbNameTxt = _errorAddress + @"\ErrorDelete" + DateTime.Now.ToLongDateString() + ".txt";
         StreamWriter Stream    = new StreamWriter(dbNameTxt, true);
         Stream.WriteLine("删除文件失败。错误为:" + ex.Message + ";文件名为:" + fileName + "时间:)" + DateTime.Now.ToString());
         Stream.Close();
         return(false);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 下载
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="fileName"></param>
 /// <param name="dirName"></param>
 /// <returns></returns>
 public bool Download(string filePath, string fileName, string dirName)////上面的代码实现了从ftp服务器下载文件的功能
 {
     try
     {
         Uri    FtpUEI = new Uri(_ftpServerIp + filePath);
         clsFTP cf     = new clsFTP(FtpUEI, _ftpUserID, _ftpPassword);
         bool   b      = cf.DownloadFile(fileName, DownPath, dirName);
         if (b)
         {
             //Stream = new StreamWriter(dbNameTxt, true);
             //Stream.WriteLine("获取文件成功。文件名为:" + fileName + "时间:)" + DateTime.Now.ToString());
             //Stream.Close();
             return(true);
         }
         else
         {
             string       dbTxt = _errorAddress + @"\ErrorGet" + DateTime.Now.ToLongDateString() + ".txt";
             StreamWriter Strea = new StreamWriter(dbTxt, true);
             Strea.WriteLine("获取文件失败。错误信息为" + cf.ErrorMsg + " 文件名为:" + fileName + "时间:)" + DateTime.Now.ToString());
             Strea.Close();
             return(false);
         }
     }
     catch (Exception ex)
     {
         string       dbNameTxt = _errorAddress + @"\ErrorGet" + DateTime.Now.ToLongDateString() + ".txt";
         StreamWriter Stream    = new StreamWriter(dbNameTxt, true);
         Stream.WriteLine("获取文件失败。错误为:" + ex.Message + ";文件名为:" + fileName + "时间:)" + DateTime.Now.ToString());
         Stream.Close();
         return(false);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 获取目录
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private FileStruct[] GetDirectorList(string path)
        {
            try
            {
                Uri          ftpUei  = new Uri(_ftpServerIp + path);
                clsFTP       cf      = new clsFTP(ftpUei, _ftpUserID, _ftpPassword);
                FileStruct[] filestr = cf.ListDirectories();

                string       dbNameTxt = _errorAddress + @"\GetDirectory" + DateTime.Now.ToLongDateString() + ".txt";
                StreamWriter stream    = new StreamWriter(dbNameTxt, true);
                stream.WriteLine("获取文件目录成功。" + "目录个数为:" + filestr.Length + "时间:)" + DateTime.Now.ToString());
                stream.Close();

                return(filestr);
            }
            catch (Exception ex)
            {
                string       dbNameTxt = _errorAddress + @"\ErrorGetDirectory" + DateTime.Now.ToLongDateString() + ".txt";
                StreamWriter stream    = new StreamWriter(dbNameTxt, true);
                stream.WriteLine("获取文件目录失败。异常为:" + ex.Message + "时间:)" + DateTime.Now.ToString());
                stream.Close();
                FileStruct[] filestr = new FileStruct[0];
                return(filestr);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 创建文件
        /// </summary>
        /// <param name="filePath">路径</param>
        /// <param name="dirName">文件名</param>
        /// <param name="ip"></param>
        /// <param name="uid"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool MakeDir(string filePath, string dirName, string ip, string uid, string pwd)
        {
            try
            {
                var  dbNameTxt = _errorAddress + @"\Create" + DateTime.Now.ToLongDateString() + ".txt";
                var  ftpUei    = new Uri(ip + filePath);
                var  cf        = new clsFTP(ftpUei, uid, pwd);
                bool b;
                if (!cf.DirectoryExist(dirName))
                {
                    b = cf.MakeDirectory(dirName);
                }
                else
                {
                    return(true);
                }
                if (b)
                {
                    var stream = new StreamWriter(dbNameTxt, true);
                    stream.WriteLine("创建目录成功。目录名为:" + dirName + "时间:)" + DateTime.Now.ToString());
                    stream.Close();
                    return(true);
                }
                else
                {
                    var dbTxt = _errorAddress + @"\ErrorCreate" + DateTime.Now.ToLongDateString() + ".txt";
                    var strea = new StreamWriter(dbTxt, true);
                    strea.WriteLine("创建目录失败。错误信息为" + cf.ErrorMsg + " 目录名为:" + dirName + "时间:)" + DateTime.Now.ToString());
                    strea.Close();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.IndexOf("远程服务器返回错误: (550)", System.StringComparison.Ordinal) >= 0)
                {
                    var ftpUei = new Uri(_ftpServerIp + filePath);
                    var cf1    = new clsFTP(ftpUei, _ftpUserID, _ftpPassword);
                    if (!cf1.DirectoryExist(dirName))
                    {
                        cf1.MakeDirectory(dirName);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    var dbNameTxt = _errorAddress + @"\ErrorCreate" + DateTime.Now.ToLongDateString() + ".txt";
                    var stream    = new StreamWriter(dbNameTxt, true);
                    stream.WriteLine("创建文件失败。错误为:" + ex.Message + ";目录名为:" + dirName + "时间:)" + DateTime.Now.ToString());
                    stream.Close();
                    return(false);
                }
            }

            return(false);
        }
Beispiel #6
0
 public bool UploadFile(string filePath, string locufullPath, string ip, string uid, string pwd)
 {
     try
     {
         var dbNameTxt = _errorAddress + @"\UpLoad" + DateTime.Now.ToLongDateString() + ".txt";
         var ftpUei    = new Uri(ip + filePath);
         var cf        = new clsFTP(ftpUei, uid, pwd);
         var b         = cf.UploadFile(locufullPath);
         if (!b)
         {
             b = cf.UploadFile(locufullPath);
         }
         if (b)
         {
             var stream = new StreamWriter(dbNameTxt, true);
             stream.WriteLine("上传文件成功。文件名为:" + locufullPath + "时间:)" + DateTime.Now.ToString());
             stream.Close();
             return(true);
         }
         else
         {
             string dbxt  = _errorAddress + @"\ErrorDelete" + DateTime.Now.ToLongDateString() + ".txt";
             var    strea = new StreamWriter(dbxt, true);
             strea.WriteLine("上传文件失败。错误信息为" + cf.ErrorMsg + " 文件名为:" + locufullPath + "时间:)" + DateTime.Now.ToString());
             strea.Close();
             return(false);
         }
     }
     catch (Exception ex)
     {
         var dbNameTxt = _errorAddress + @"\ErrorDelete" + DateTime.Now.ToLongDateString() + ".txt";
         var stream    = new StreamWriter(dbNameTxt, true);
         stream.WriteLine("上传文件失败。错误为:" + ex.Message + ";文件名为:" + locufullPath + "时间:)" + DateTime.Now.ToString());
         stream.Close();
         return(false);
     }
 }