0

我从 FTP 下载文件时遇到了一个小问题。我收到一条错误消息,提示“远程服务器返回错误 (550) 文件不可用(例如,找不到文件,无法访问)。”

代码如下:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void btntamam_Click(object sender, EventArgs e)
    {
     FtpWebRequest FTP;

try
{

FileStream SR = new FileStream("C:\\asd" + "\\list.gz", FileMode.Create);

FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://xx.x.xx.xxx/" + "list.gz"));

FTP.Credentials = new NetworkCredential("username", "pass");

FTP.Method = WebRequestMethods.Ftp.DownloadFile;

FTP.UseBinary = true;

FtpWebResponse response = (FtpWebResponse)FTP.GetResponse();

Stream ftpStream = response.GetResponseStream();

long cl = response.ContentLength;

int bufferSize = 2048;
int readCount;

byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
    SR.Write(buffer, 0, readCount);
    readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
SR.Close();
response.Close();
MessageBox.Show("File Downloaded!");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
    }
}
}

该代码似乎正在运行,但无法下载我想要的文件。我已经搜索了很多但找不到任何解决方案..

4

0 回答 0