zoukankan      html  css  js  c++  java
  • C# FTP下载文件

                保存路径    文件夹        文件名

    private void Download(string filePath, string filesName, string fileName)
    {
    FtpWebRequest reqFTP;
    try
    {
    //filePath = <<The full path where the file is to be created.>>,
    //fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
    string str_path =filePath + "\" + fileName;
    FileStream outputStream = new FileStream(str_path, FileMode.Create);
    string uri = "ftp://" + ftpServerIP + "/" + filesName + "/" + fileName;
    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
    reqFTP.UseBinary = true;
    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
    FtpWebResponse response = (FtpWebResponse)reqFTP.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)
    {
    outputStream.Write(buffer, 0, readCount);
    readCount = ftpStream.Read(buffer, 0, bufferSize);
    }
    ftpStream.Close();
    outputStream.Close();
    response.Close();
    }

  • 相关阅读:
    记事本开发者日记~二
    《梦断代码》读后感①
    记事本开发日记~一
    仓库管理msi系统
    java web + mysql 的增删改查
    第九周动手动脑
    四则运算答题版
    JAVA常用的异常处理情况
    继承和多态中动手动脑
    laravel1
  • 原文地址:https://www.cnblogs.com/wlwenjie/p/5048512.html
Copyright © 2011-2022 走看看