我使用下面的c#代码连接FTP服务器。有时在发送文件时,它会收到错误代码551和说明:发送FTP时发现异常:远程服务器返回错误:(551)页面类型未知。
我不知道为什么会这样。 谁能告诉我这是什么问题?
private bool sendFTP(string sDestPath, string sFileName, string sUserName, string sPassword, string sDomain, bool isProxyUsed, string sProxy, int nProxyPort, byte[] sData)
{
try
{
NetworkCredential nCred;
if (!sDomain.Equals(String.Empty))
{
nCred = new System.Net.NetworkCredential(sUserName, sPassword, sDomain);
}
else
{
nCred = new System.Net.NetworkCredential(sUserName, sPassword);
}
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(sDestPath + "//" + sFileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = nCred;
request.Proxy = new WebProxy();
if (isProxyUsed)
{
WebProxy p = new WebProxy(sProxy, nProxyPort);
p.Credentials = nCred;
WebRequest.DefaultWebProxy = p;
}
request.ContentLength = sData.Length;
Stream reqStream = request.GetRequestStream();
reqStream.Write(sData, 0, sData.Length);
reqStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
return true;
}
catch (Exception objEx)
{
// Error
EventLog.WriteEntry("STCCommon", "Exception Caught:" + objEx.Message, EventLogEntryType.Error);
throw new Exception("Exception caught in sending FTP: " + objEx.Message);
}
}