生活本来就刺激 2016-06-05 09:38 采纳率: 0%
浏览 8751

c#对路径访问被拒绝怎么办?

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

    }
            求大神帮忙看一下好吗
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥20 怎么在stm32门禁成品上增加记录功能
    • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
    • ¥50 NT4.0系统 STOP:0X0000007B
    • ¥15 想问一下stata17中这段代码哪里有问题呀
    • ¥15 flink cdc无法实时同步mysql数据
    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 解riccati方程组