zoukankan      html  css  js  c++  java
  • c#Ftp上传文件

    public string UploadFile(string filePath, string fileName, string ftpServerIP, string ftpUserName, string ftpPassword)
    {
    string file = filePath + fileName;
    FileInfo fileInf = new FileInfo(file);

    string uri = "ftp://" + ftpServerIP + @"/" + fileInf.Name;
    FtpWebRequest reqFtp = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
    reqFtp.Credentials = new NetworkCredential(ftpUserName, ftpPassword);

    reqFtp.Method = WebRequestMethods.Ftp.UploadFile;

    reqFtp.UsePassive = false;
    reqFtp.UseBinary = true;
    int buffLength = 2048;
    byte[] buff = new byte[buffLength];
    int contentLen = 0;
    FileStream fs = fileInf.OpenRead();
    try
    {
    Stream strm = reqFtp.GetRequestStream();

    contentLen = fs.Read(buff, 0, buffLength);

    while (contentLen != 0)
    {
    strm.Write(buff, 0, contentLen);

    contentLen = fs.Read(buff, 0, buffLength);
    }
    strm.Close();
    fs.Close();
    }
    catch (Exception ex)
    {
    fs.Close();
    return ex.StackTrace;
    }
    return "文件上传成功";
    }

  • 相关阅读:
    blktrace分析IO
    Mac-配置SecureCRT
    Mac-安装itellij idea
    Mac-sublime text 3破解版
    Mac-item+zsh
    Mac-安装homebrew
    Mac-装机
    Mac-WIFI总是断网
    Git-ssh登录github
    Git-回滚操作
  • 原文地址:https://www.cnblogs.com/xwchengc/p/6343869.html
Copyright © 2011-2022 走看看