can someone show me an example script of开发者_运维技巧 how I would upload picturebox1's Image to an FTP connection?
This ought to do it with just plain .NET classes:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using ms As New System.IO.MemoryStream
PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Using wc As New System.Net.WebClient
wc.UploadData("ftp://foo.com/bar/mumble.png", ms.ToArray())
End Using
End Using
End Sub
Sounds like your PictureBox
has a source that's an image on disk. If it's not, find a way to save that image to disk.
Use this VB.NET FTP client library to upload that image to your FTP destination. It wraps all the logic needed, and will save you the time of writing the code yourself.
It uses System.Net.FtpWebRequest
.
myFtp.Upload("C:\myimage.png", "/pub/someImage.png")
Dim username = "USERNAME"
Dim password = "PASSWORD"
Dim hostname = "http://www.wherethefilewillappear.com/directory1/"
Dim server = "ftp://ftp.yoursite.com/"
My.Computer.Network.UploadFile("C:\text.txt", server &"/text.txt", username, password)
Easy as that.
精彩评论