C# 没有使用c连接到ftp#

C# 没有使用c连接到ftp#,c#,download,ftp,filestream,ftpwebrequest,C#,Download,Ftp,Filestream,Ftpwebrequest,我可以创建一个文件夹,我可以重命名文件,但我不能上传和下载文件到ftp。显示的异常为System.Net.WebException:远程服务器返回错误:(500)语法错误,无法识别命令 有人知道为什么吗 日志文件: System.Net信息:0:[6112]FtpControlStream#7746814-不支持Resposta recebida[500端口/EPRT(活动模式/扩展活动模式)。请使用PASV/EPSV代替此] 系统.Net信息:0:[6112]FtpWebRequest#309

我可以创建一个文件夹,我可以重命名文件,但我不能上传和下载文件到ftp。显示的异常为System.Net.WebException:远程服务器返回错误:(500)语法错误,无法识别命令

有人知道为什么吗

日志文件:
System.Net信息:0:[6112]FtpControlStream#7746814-不支持Resposta recebida[500端口/EPRT(活动模式/扩展活动模式)。请使用PASV/EPSV代替此]
系统.Net信息:0:[6112]FtpWebRequest#30923613::(Liberando a conexão de FTP#7746814.)
系统.Net错误:0:[6112]异常FtpWebRequest#30923613::GetRequestStream-o servidor remoto Returnou um erro:(500)erro de sintaxe,comando não reconhecido.

代码:


我的问题是卡巴斯基防病毒软件阻塞了通信端口。

即使用
ftpRequest.useAnsive=true,除非你有很好的理由不这么做。如果我使用ftpRequest.useAnsive=true;显示的例外情况是:远程服务器返回一个错误:227进入被动模式(201,23,75,26225,86),您是否尝试用谷歌搜索该错误消息?如果您这样做了,并且建议的解决方案都没有帮助,请编辑您的问题,以获得新的代码和错误。并确保至少包含一个日志文件:Stream ftpStream=ftpRequest.GetRequestStream()命令中出现错误;对不起,这是我第一次在这里提问。我已经读了好几篇文章,但我没有找到解决这个问题的方法。每次传入流时,逗号ftpStream=ftpRequest.GetRequestStream();抛出异常。我已经在另一个ftp上测试过了,同样的问题也发生了。我不知道还能做什么。请不要发布重复的答案:-你应该在问之前用谷歌搜索答案!
 /* 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;
}