C# FTP,GetResponse(),远程服务器返回错误:(550) 文件不可用(例如,未找到文件,无法访问文件)

namespace 访问第三方FTP服务器cc
{
public partial class Form1 : Form
{
IPAddress ip = null;
int port = 0;
string userid = "lr", pwd = "lr";
FtpWebRequest reqftp = null;
public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
try
{
this.ip = IPAddress.Parse(this.textBox1.Text.Trim());

}
catch
{
MessageBox.Show("您输入的IP地址格式不对!");
}
try
{
this.port=Int32.Parse(this.textBox2.Text.Trim());
}
catch
{
MessageBox.Show("请输入一个正整数作为端口号");
}
}
private void button3_Click(object sender, EventArgs e)
{
FtpWebRequest ftpreq;
try
{
string filename = this.comboBox1.SelectedIndex.ToString();
FolderBrowserDialog save = new FolderBrowserDialog();
DialogResult dr = save.ShowDialog();
if (dr == DialogResult.OK)
{
ftpreq = (FtpWebRequest)FtpWebRequest.Create("ftp://"+ ip + "/" + filename);
ftpreq.Credentials = new NetworkCredential(userid, pwd);
ftpreq.Method = WebRequestMethods.Ftp.DownloadFile;
this.toolStripStatusLabel1.Text = "文件下载.....";
FtpWebResponse response = (FtpWebResponse)ftpreq.GetResponse();
Stream ftpstream = response.GetResponseStream();
long filelen = response.ContentLength;
byte[] buffer = new byte[2048];
int readcount = ftpstream.Read(buffer, 0, 2048);
FileStream file = new FileStream(save.SelectedPath + "//" + filename, FileMode.Create);
while (readcount > 0)
{
file.Write(buffer, 0, readcount);
readcount = ftpstream.Read(buffer, 0, 2048);

}
ftpstream.Close();
response.Close();
this.toolStripStatusLabel1.Text = "文件下载完毕!";
MessageBox.Show("文件下载完毕!");
}
else
{
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "下载失败!");
this.toolStripStatusLabel1.Text = "下载失败!"+ex.Message.ToString();
}
}

第1个回答  2009-12-15
建议你调试一下,查查你请求的地址以及文件路径是否正确,注意,这里使用的文件地址应该是相对你登陆账号的工作目录的相对路径。本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网