C# FTP over SSL问题
我在通过SSL将文件上载到ftp站点到特定目录时遇到问题。为此,我正在使用C# FTP over SSL问题,c#,ssl,ftp,C#,Ssl,Ftp,我在通过SSL将文件上载到ftp站点到特定目录时遇到问题。为此,我正在使用System.Net.FtpWebRequest类。上传进展顺利。但是该文件总是被放到主目录中。你知道什么地方做错了吗?谢谢你的帮助 public bool UploadFile(string srcFilePath, string destFilePath = null) { if (String.IsNullOrWhiteSpace(srcFilePath)) t
System.Net.FtpWebRequest
类。上传进展顺利。但是该文件总是被放到主目录中。你知道什么地方做错了吗?谢谢你的帮助
public bool UploadFile(string srcFilePath, string destFilePath = null)
{
if (String.IsNullOrWhiteSpace(srcFilePath))
throw new ArgumentNullException("Source FilePath.");
if (String.IsNullOrWhiteSpace(destFilePath))
destFilePath = Path.GetFileName(srcFilePath);
Uri serverUri = GetUri(destFilePath);
//// the serverUri should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
return false;
// get the object used to communicate with the server.
FtpWebRequest request = CreateFtpRequest(serverUri, WebRequestMethods.Ftp.UploadFile);
// read file into byte array
StreamReader sourceStream = new StreamReader(srcFilePath);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
// send bytes to server
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Debug.WriteLine("Response status: {0} - {1}", response.StatusCode, response.StatusDescription);
return true;
}
private FtpWebRequest CreateFtpRequest(Uri serverUri, string method)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.EnableSsl = true;
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Credentials = new NetworkCredential(_userName, _password);
request.Method = method;
return request;
}
private Uri GetUri(string remoteFilePath)
{
return new Uri(_baseUri, remoteFilePath);
}
嗯。我终于明白了。这是.NET4.0框架问题。使用.NET3.5构建解决方案,效果非常好
讨厌在微软新发布的.NET中看到bug,浪费大量的时间来解决问题。如果不显示您的代码,就不可能有人能帮助您。Raj
当您在这里调试这行代码时Uri serverUri=GetUri(destFilePath)
serverUri的确切值是多少?ftp路径解析为正确的路径。但是文件被传送到了