相关疑难解决方法(0)

ftp上传太大了

我在C#中编写了一个函数,用于在复制到文件共享时无法上传文件.我注意到任何上传的文件大小都是原始文件的1.5-2倍,并且是无效文件.这是代码:

public bool save_FTPUpload(FileInfo fi_attachment)
{
    bool fileSaved = false;
    string filename = fi_attachment.Name;

    while (!fileSaved)
    {
        string file_ftpURI = string.Format("{0}/{1}", ftpURI, filename);
        FtpWebRequest file_exist_request = (FtpWebRequest)FtpWebRequest.Create(file_ftpURI);
        file_exist_request.Credentials = new NetworkCredential(ftp_user, ftp_pass);
        file_exist_request.Method = WebRequestMethods.Ftp.GetFileSize;
        try
        {
            FtpWebResponse response = (FtpWebResponse)file_exist_request.GetResponse();
        }
        catch (WebException ex)
        {
            FtpWebResponse response = (FtpWebResponse)ex.Response;
            if (response.StatusCode ==
                FtpStatusCode.ActionNotTakenFileUnavailable)
            {
                FtpWebRequest upload_request = (FtpWebRequest)FtpWebRequest.Create(file_ftpURI);
                upload_request.Credentials = new NetworkCredential(ftp_user, ftp_pass);

                upload_request.Method = WebRequestMethods.Ftp.UploadFile;
                upload_request.UsePassive = true;
                upload_request.UseBinary = true;
                upload_request.KeepAlive = false;

                StreamReader attachment = new …
Run Code Online (Sandbox Code Playgroud)

.net c# ftp vsto network-programming

2
推荐指数
1
解决办法
1137
查看次数

标签 统计

.net ×1

c# ×1

ftp ×1

network-programming ×1

vsto ×1