从ftp服务器上下载东西到本地,报错对路径访问被拒绝。
这是下载函数
public void DownloadFile(string localFile, string remoteFile)
{
FtpWebRequest ftp = CreateFtpRequest(string.Format("{0}/{1}", _ftpURI, remoteFile));
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
byte[] buffer = new byte[2048 * 8];
using (FileStream fs = new FileStream(localFile, FileMode.Create, FileAccess.Write))
{
int count = stream.Read(buffer, 0, buffer.Length);
while (count > 0)
{
fs.Write(buffer, 0, count);
count = stream.Read(buffer, 0, buffer.Length);
}
fs.Close();
}
stream.Close();
}
response.Close();
}
MessageBox.Show("下载完成!");
}
执行如下
private void skinButton2_Click(object sender, EventArgs e)
{
string localPath = "";
FolderBrowserDialog fd = new FolderBrowserDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
localPath = fd.SelectedPath;
}
FTPHelper user = new FTPHelper("127.0.0.1", "user88", "123");
MessageBox.Show(localPath);
user.DownloadFile(localPath, fileName);
}
求大神帮忙看一下好吗