C# FTP,GetResponse(),远程服务器返回错误:(550) 文件不可用(例如,未找到文件,无法访问文件)
namespace访问第三方FTP服务器cc{publicpartialclassForm1:Form{IPAddressip=null;intport=0;string...
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();
}
} 展开
{
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个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询