简体   繁体   English

从PictureBox上传图像到FTP

[英]Upload image to FTP from PictureBox

  • in my C# desktop application there is picturebox and loaded with an image. 在我的C#桌面应用程序中,有图片框并装有图像。
  • i just want to upload this image to FTP without save image to 我只想将此图像上传到FTP而不保存图像到
    local pc. 本地电脑
  • how do i do that ? 我怎么做 ?

Maybe I Think You Are Trying To Upload A Image File To FTP This Code Is Work For You 也许我认为您正在尝试将图像文件上传到FTP,此代码对您有用

You Have To Crete A FTP Web Request 您必须创建一个FTP Web请求

FtpWebRequest request =(FtpWebRequest)WebRequest.Create(" ftp://www.yourftp.com "); FtpWebRequest request =(FtpWebRequest)WebRequest.Create(“ ftp://www.yourftp.com ”);

request.Method = WebRequestMethods.Ftp.UploadFile; request.Method = WebRequestMethods.Ftp.UploadFile;

request.Credentials = new NetworkCredential ("username","password"); request.Credentials =新的NetworkCredential(“用户名”,“密码”);

string flepath="Locationoffile"; 字符串flepath =“ Locationoffile”;

FileStream stream = File.OpenRead(filePath); FileStream流= File.OpenRead(filePath);

byte[] buffer = new byte[stream.Length]; byte []缓冲区=新的byte [stream.Length];

stream.close(); stream.close();

request.ContentLength=buffer.Length; request.ContentLength = buffer.Length;

Stream requestsream=request.GetRequestStream(); 流requestsream = request.GetRequestStream();

requestStream.Write(buffer,0,buffer.Lenght); requestStream.Write(buffer,0,buffer.Lenght);

requestStream.Close(); requestStream.Close();

FtpWebResponse response=(FtpWebResponse)request.GetResponse(); FtpWebResponse response =(FtpWebResponse)request.GetResponse();

response.Close(); response.Close();

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

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