我可以創建一個文件夾,我可以重命名該文件,但我無法上傳和下載文件到ftp。顯示的異常是System.Net.WebException:遠程服務器返回錯誤:(500)語法錯誤,命令無法識別。沒有連接到ftp使用c#
任何人都有一個想法,爲什麼?
日誌文件: System.Net Information: 0 : [6112] FtpControlStream#7746814 - Resposta recebida [500 PORT/EPRT (Active Mode/Extended Active Mode) is not supported. Use PASV/EPSV instead of this] System.Net Information: 0 : [6112] FtpWebRequest#30923613::(Liberando a conexão de FTP#7746814.) System.Net Error: 0 : [6112] Exceção em FtpWebRequest#30923613::GetRequestStream - O servidor remoto retornou um erro: (500) Erro de sintaxe, comando não reconhecido.
代碼:
/* Upload File */
public void upload(string remoteFile, string localFile)
{
try
{
/* Create an FTP Request */
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + remoteFile);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential(user, pass);
/* When in doubt, use these options */
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = false;
ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
/* Establish Return Communication with the FTP Server */
Stream ftpStream = ftpRequest.GetRequestStream();
/* Open a File Stream to Read the File for Upload */
FileStream localFileStream = new FileStream(localFile, FileMode.Create);
/* Buffer for the Downloaded Data */
byte[] byteBuffer = new byte[bufferSize];
int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
/* Upload the File by Sending the Buffered Data Until the Transfer is Complete */
try
{
while (bytesSent != 0)
{
ftpStream.Write(byteBuffer, 0, bytesSent);
bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
}
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
/* Resource Cleanup */
localFileStream.Close();
ftpStream.Close();
ftpRequest = null;
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
return;
}
的可能的複製[定影 - System.Net.WebException:遠程服務器返回錯誤:(500)語法錯誤,不可識別的命令(https://stackoverflow.com/questions/21221300/fixing-system-net- webexception-the-remote-server-returned-an-error-500-syn) –
Ie使用'ftpRequest.UsePassive = true;',除非你有一個非常好的**理由不要。 –
如果我使用ftpRequest.UsePassive = true;顯示的異常是:遠程服務器返回一個錯誤:227進入被動模式(201,23,75,26,225,86) –