im trying to take a screenshot of my desktop and send it to my FTP server the screenshot gets saved in TEMP folder and then uploaded.
here is the FTP upload code
Public Sub FTPScreen(ByVal _FileName As String, ByVal _UploadPath As String, ByVal _FTPUser As String, ByVal _FTPPass As String)
Try
Dim _FileInfo As New System.IO.FileInfo(_FileName)
' Create FtpWebRequest object from the Uri provided
Dim _FtpWebRequest As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(New Uri(_UploadPath)), System.Net.FtpWebRequest)
' Provide the WebPermission Credintials
_FtpWebRequest.Credentials = New System.Net.NetworkCredential(_FTPUser, _FTPPass)
' By default KeepAlive is true, where the control connection is not closed
' after a command is executed.
_FtpWebRequest.KeepAlive = False
' set timeout for 20 seconds
_FtpWebRequest.Timeout = 20000
' Specify the command to be executed.
_FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' Specify the data transfer type.
_FtpWebRequest.UseBinary = True
' Notify the server about the size of the uploaded file
_FtpWebRequest.ContentLength = _FileInfo.Length
' The buffer size is set to 2kb
Dim buffLength As Integer = 2048
Dim buff(buffLength - 1) As Byte
' Opens a file stream (System.IO.FileStream) to read the file to be uploaded
Dim _FileStream As System.IO.FileStream = _FileInfo.OpenRead()
Try
' Stream to which the file to be upload is written
Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestStream()
' Read from the file stream 2kb at a time
Dim contentLen As Integer = _FileStream.Read(buff, 0, buffLength)
' Till Stream content ends
Do While contentLen <> 0
' Write Content from the file stream to the FTP Upload Stream
_Stream.Write(buff, 0, contentLen)
contentLen = _FileStream.Read(buff, 0, buffLength)
Loop
' Close the file stream and the Request Stream
_Stream.Close()
_Stream.Dispose()
_FileStream.Close()
_FileStream.Dispose()
Catch ex As Exception
End Try
and here is the method to upload the screenshot
Try
Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.Temp & "\ScreenShot"
' save the screenshot to temp folder
Dim screenshot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screengrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screengrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenshot)
screengrab.Save(SnapDir) ' screenshot saved
FTPScreen(SnapDir, "ftp://ftp.morlza1.zz.mu/" & "2015" & My.Computer.Name, "user", "pass")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Catch ex As Exception
End Try
End Sub
the screenshot does get saved to my temp folder and i can view it with no problem. but when i upload it to FTP. 2 things happen 1- the image size increases by 1 K 2- the image gets corrupt and it can't be viewed
i did include a try
statement to check for any error for there is no error so its a code mistake i guess