C# 上传图片到FTP服务器,出现了错误,代码是我复制的,不知道哪个环节出现了错误,求高手指点感激不尽,,

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Net;
    using System.IO;
    using System.Globalization;
    using System.Text.RegularExpressions;
    //调用
    UploadFile(txtpath.Text,filename,false);
            /// <summary>
            /// 上传文件到FTP服务器
            /// </summary>
            /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
            /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
            /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
            public bool UploadFile(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)
            {
                try
                {
                    if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(Path.GetFileName(LocalFullPath)) || !IsValidPathChars(Path.GetDirectoryName(LocalFullPath)))
                    {
                        throw new Exception("非法文件名或目录名!");
                    }
                    if (File.Exists(LocalFullPath))
                    {
                        FileStream Stream = new FileStream(LocalFullPath, FileMode.Open, FileAccess.Read);
                        byte[] bt = new byte[Stream.Length];
                        Stream.Read(bt, 0, (Int32)Stream.Length);   //注意,因为Int32的最大限制,最大上传文件只能是大约2G多一点
                        Stream.Close();
                        return UploadFile(bt, RemoteFileName, OverWriteRemoteFile);
                    }
                    else
                    {
                        throw new Exception("本地文件不存在!");
                    }
                }
                catch (Exception ep)
                {
                    ErrorMsg = ep.ToString();
                    throw ep;
                }
            }
      

  2.   

    IsValidFileChars, ErrorMsg 等的定义在哪里?
      

  3.   

    你复制的肯定不全。
    IsValidFileChars, ErrorMsg 可能在别的文件里