我可以创建一个文件夹,我可以重命名该文件,但我无法上传和下载文件到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) –