FTP重命名方法备份

///// <summary>
///// 重命名
///// </summary>
///// <param name="ftpFileName">2019-07-01\\123456.pdf </param>
///// <param name="newFilename">987654.pdf</param>
//public static bool FileRename(string ftpFileName, string newFileName)
//{
// bool isExist = false;//文件是否存在
// string ftpRootURL = CurrentParams.Instance.ImgFtpConnectionInfos[0].Host;
// FtpWebRequest ftpWebRequest = null;
// FtpWebResponse ftpWebResponse = null;
// try
// {
// if (currentServerAdd != "")
// {
// ftpRootURL = currentServerAdd;
// }
// string address = "ftp://"+ ftpRootURL + "//" + ftpFileName;
// ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(address));
// ftpWebRequest.Timeout = 1500;
// ftpWebRequest.Credentials = new NetworkCredential(CurrentParams.Instance.FtpUserName, CurrentParams.Instance.FtpPassword);
// ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
// ftpWebRequest.GetResponse();
// isExist = true;
// }
// catch (Exception ex)
// {
// isExist = false;
// }
// finally
// {
// if (ftpWebResponse != null)
// {
// ftpWebResponse.Close();
// }
// if (ftpWebRequest != null)
// {
// ftpWebRequest.Abort();
// }
// }
// if (!isExist)//文件不存在直接返回true
// {
// return true;
// }
// try
// {
// //重命名操作
// string uri = "ftp://"+ ftpRootURL +"//"+ ftpFileName;
// ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
// ftpWebRequest.Credentials = new NetworkCredential(CurrentParams.Instance.FtpUserName, CurrentParams.Instance.FtpPassword);
// ftpWebRequest.Timeout = 1500;
// ftpWebRequest.Method = WebRequestMethods.Ftp.Rename;
// ftpWebRequest.RenameTo = newFileName;
// ftpWebResponse = (FtpWebResponse)ftpWebRequest.GetResponse();

// }
// catch (Exception ex)
// {
// MessageBoxHelper.ShowError(App.openForm, "重命名FTP文件失败!\n" + ex.Message);
// return false;
// }
// finally
// {
// if (ftpWebRequest != null)
// {
// ftpWebRequest.Abort();
// }
// if (ftpWebResponse != null)
// {
// ftpWebResponse.Close();
// }
// }
// return true;
//}

猜你喜欢

转载自www.cnblogs.com/Tim-Zhang/p/12144935.html