错误550从FTP下载时文件不可用

时间:2013-07-17 08:12:00

标签: c# ftp download

从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");
}
    }
}
}

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

0 个答案:

没有答案