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();
    }

  • 相关阅读:
    BDB c++例子,从源码编译到运行
    Linux的nm查看动态和静态库中的符号
    转:js包装DOM对象
    svn笔记4属性Properties
    c++ 友元函数
    转:js包装DOM对象
    整除规则(原理,性质)
    回溯法求幂集
    转:Javascript继承机制的设计思想
    javascript prototype __proto__区别
  • 原文地址:https://www.cnblogs.com/wlwenjie/p/5048512.html
Copyright © 2011-2022 走看看