Hi. I'm fairly new to VB. I've made a handful of small programs and followed a few tutorials, but this is really the most complex program I've made so far. (Just a heads up that I may be missing something fairly obvious :$)
I'm working on a VB program which shrinks an image and sends it to a server over FTP. I found the following code snippet on another forum a week or two back (I can't recall exactly where), but I'm having a bit of an issue with it.
Private Sub FTP()
'Variables
Dim cls_request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(My.Settings.url), System.Net.FtpWebRequest)
'Establish credentials for logging into ftp site
cls_request.Credentials = New System.Net.NetworkCredential(My.Settings.username, My.Settings.password)
'Set properties
cls_request.KeepAlive = False
cls_request.Proxy = Nothing
cls_request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
cls_request.UseBinary = True
'Read in the file
Dim b_file() As Byte = System.IO.File.ReadAllBytes(OpenFileDialog1.FileName)
'Upload the file
! cls_request.GetRequestStream.Write(b_file, 0, b_file.Length)
cls_request.GetRequestStream.Close()
cls_request.GetRequestStream.Dispose()
MessageBox.Show("Success")
End Sub
When I run it, I get "A first chance exception of type 'System.Net.WebException' occurred in System.dll" and an error stating "The requested URI is invalid for this FTP command" in the code window. The program itself freezes. (I marked the line with an !)
From what I can tell, the issue seems to be that there is no filename specified for the upload, but I'm not sure how I would add that. (or even if that's the problem :confused:)
I've worked at this issue for a few hours and haven't made any progress, so I'm hoping someone will be able to help me solve this annoying error.
Thanks!