我在win7系统下运行我写的c#服务,通过服务给linux的ftp传文件,传输成功后修改ftp目录下文件名,但是win7 32位系统下可以正常重命名,但是到win7 64位系统下,linux监测文件改名时,修改的名字前会有一个多余的“/”,但是ftp下重命名的文件不会有多余的“/”,求助大神为什么会出现这个“/”,附上代码
bool isSuccess = ftpHelper.fileUpload(file, ftpSource.FilePath, fileNewName);
if (isSuccess)
{
DataTable svrDataTable = ServerCom.ExeSqlForDataTable("select * from totalstream where isupload=0");
long sum = 0;
string fileName = string.Empty;
foreach (DataRow row in svrDataTable.Rows)
{
if (row["FileZipName"].ToString() == file.Name.ToString())
{
fileName = row["FileName"].ToString();
sum = Convert.ToInt64(row["StreamNum"]);
break;
}
}
DateTime time = DateTime.Now;
ftpHelper.fileRename(ftpSource.FilePath, fileNewName, fileName.Replace("txt", "zip"));
file.CopyTo(file.DirectoryName + "/" + fileName.Replace("txt", "zip"));
file.Delete();
}
/// <summary>
/// 重命名
/// </summary>
/// <param name="ftpPath">ftp文件路径</param>
/// <param name="currentFilename"></param>
/// <param name="newFilename"></param>
public bool fileRename(string ftpPath, string currentFileName, string newFileName)
{
bool success = false;
FtpWebRequest ftpWebRequest = null;
FtpWebResponse ftpWebResponse = null;
Stream ftpResponseStream = null;
try
{
string uri = ftpRootURL + ftpPath + currentFileName;
ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
ftpWebRequest.UseBinary = true;
ftpWebRequest.Method = WebRequestMethods.Ftp.Rename;
ftpWebRequest.RenameTo = newFileName;
ftpWebResponse = (FtpWebResponse)ftpWebRequest.GetResponse();
ftpResponseStream = ftpWebResponse.GetResponseStream();
}
catch (Exception)
{
success = false;
}
finally
{
if (ftpResponseStream != null)
{
ftpResponseStream.Close();
}
if (ftpWebResponse != null)
{
ftpWebResponse.Close();
}
}
return success;
}
目前在win10上可正常传输,win7、winserver都不行