繁体   English   中英

如何从Windows窗体picturbox上传图像到FTP服务器?

[英]How to upload image from windows form picturbox to FTP server?

我有一个带有图片框的表格。 首先,我用本地计算机上的图片加载图片框。 现在,我想将图片上传到ftp服务器。

我不明白如何获取图片框的文件路径。 还是还有其他方法?

public void UploadImage(PictureBox image, string filename)
{
    using (WebClient client = new WebClient())
    {
   client.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
 client.UploadFile("ftp://127.0.0.1/Image/",WebRequestMethods.Ftp.UploadFile);

   }

}

您需要获取图片框中图片的第一个文件路径

string filepath = image.ImageLocation;

然后将此路径传递给WebClient.UploadFile

public void UploadImage(PictureBox image, string filename)
{
    string filepath = image.ImageLocation;     //<= Get image path 

    using (WebClient client = new WebClient())
    {
        client.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
        client.UploadFile("ftp://127.0.0.1/Image/", filepath);    //<= Pass this path here

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM