C# FTP上载图像错误

C# FTP上载图像错误,c#,ftp,C#,Ftp,我正在尝试将图像上载到由web主机托管的ftp服务器,以存储用户关闭和重新打开我的应用程序时的配置文件图像 注意如果有其他方法可以储存,请建议 我尝试了下面的代码,但我一直收到一个错误,说 App.exe中发生“System.Net.WebException”类型的未处理异常附加信息:远程服务器返回错误:(500)语法错误,无法识别命令 一个人对我说的一条评论是“这个错误非常普遍。这可能意味着你有防火墙或什么东西阻止了什么东西,也可能意味着服务器上不支持SSL”你们中的任何人都可以帮助处理这个评

我正在尝试将图像上载到由web主机托管的ftp服务器,以存储用户关闭和重新打开我的应用程序时的配置文件图像

注意如果有其他方法可以储存,请建议

我尝试了下面的代码,但我一直收到一个错误,说

App.exe中发生“System.Net.WebException”类型的未处理异常附加信息:远程服务器返回错误:(500)语法错误,无法识别命令

一个人对我说的一条评论是“这个错误非常普遍。这可能意味着你有防火墙或什么东西阻止了什么东西,也可能意味着服务器上不支持SSL”你们中的任何人都可以帮助处理这个评论吗。因为我不明白如何才能阻止防火墙或阻止它,或排除(如果可以的话,没有那么重要的帮助)

继续讨论主要问题。。。我的代码-(FTP部分)在公共静态类中

public static void UpLoadImage(string source)
    {
        try
        {
            String sourcefilepath = source;
            String ftpurl = "ftp://www.locu.site90.com/public_html/"; 
            String ftpusername = "a4670620";
            String ftppassword = "********";
            string filename = Path.GetFileName(source);
            string ftpfullpath = ftpurl + filename;
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);

            ftp.KeepAlive = false;
            ftp.EnableSsl = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;

            FileStream fs = File.OpenRead(source);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();

            Stream ftpstream = ftp.GetRequestStream();
            ftpstream.Write(buffer, 0, buffer.Length);
            ftpstream.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
这里是我在选择图像时称为空白的地方

private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog open = new OpenFileDialog();
        if (open.ShowDialog() == DialogResult.OK)
        {
            Bitmap bit = new Bitmap(open.FileName);
            pictureBox1.Image = bit;
            pictureBox2.Image = bit;
            bit.Dispose();
            string fullPath = open.FileName;
            string fileName = open.SafeFileName;
            string path = fullPath.Replace(fileName, "");
            User.Details.UpLoadImage(fullPath);
        }
    }

我本人对给予的任何帮助都表示100%的感谢

我正在使用以下代码创建路径:

System.Net.FtpWebRequest ftpReq = null;
System.Net.FtpWebResponse ftpRes = null;
try
{
ftpReq = System.Net.WebRequest.Create(path) as System.Net.FtpWebRequest;
ftpReq.Credentials = new System.Net.NetworkCredential(user, password);
ftpReq.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory;
ftpReq.KeepAlive = false;
ftpRes = ftpReq.GetResponse() as System.Net.FtpWebResponse;
ftpRes.Close();
}
catch (WebException we)
{
   //do something with the error
}
catch (Exception e)
{   
   //do something with the error
}
以及上传文件为什么不使用

public byte[] UploadFile(string address, string fileName):
上载到ftp的代码:

WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential(tabFolder.FldUser, tabFolder.FldPassword);
wc.UploadFile(folder.TrimEnd(@"\".ToCharArray()) + @"\" + fn, jpgFile);

或者你也可以像下面的答案那样分块发送