EDIT: I'm sorry, I was so caught up in reading the code that I forgot to add a title to my post...
Hi Neowin! I have a dilemma on my hands... I am trying to create a simple program to upload a file to our FTP server but I am having some issues. I found this piece of code on the web which should work but I keep receiving a: "The requested URI is invalid for this FTP command." error when the code reaches the upload section:
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
Also, the debugger shows multiple instances of this exception: "A first chance exception of type 'System.Net.WebException' occurred in System.dll"
Has anyone have any idea of what this means? I tried to Google it but I couldn't find a straight answer to the subject.
Private Sub cmdUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpload.Click
Log("Acquiring information")
' These should come from an XML file
ftpserver = "ftp://**********"
ftpusername = "*********"
ftppassword = "*********"
Log("Connecting to: " & ftpserver)
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(ftpserver), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(ftpusername, ftppassword)
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file
Log("Reading file")
Dim bFile() As Byte = System.IO.File.ReadAllBytes(strFilePath)
' upload file
Log("Uploading file")
clsRequest.UsePassive = False
clsRequest.Proxy = Nothing
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
' close stream
Log("Closing connection")
clsStream.Close()
clsStream.Dispose()
' complete
Log("Complete")
MsgBox("Upload complete")
End Sub
Question
redhaze
EDIT: I'm sorry, I was so caught up in reading the code that I forgot to add a title to my post...
Hi Neowin! I have a dilemma on my hands... I am trying to create a simple program to upload a file to our FTP server but I am having some issues. I found this piece of code on the web which should work but I keep receiving a: "The requested URI is invalid for this FTP command." error when the code reaches the upload section:
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
Also, the debugger shows multiple instances of this exception: "A first chance exception of type 'System.Net.WebException' occurred in System.dll"
Has anyone have any idea of what this means? I tried to Google it but I couldn't find a straight answer to the subject.
Private Sub cmdUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpload.Click Log("Acquiring information") ' These should come from an XML file ftpserver = "ftp://**********" ftpusername = "*********" ftppassword = "*********" Log("Connecting to: " & ftpserver) Dim clsRequest As System.Net.FtpWebRequest = _ DirectCast(System.Net.WebRequest.Create(ftpserver), System.Net.FtpWebRequest) clsRequest.Credentials = New System.Net.NetworkCredential(ftpusername, ftppassword) clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile ' read in file Log("Reading file") Dim bFile() As Byte = System.IO.File.ReadAllBytes(strFilePath) ' upload file Log("Uploading file") clsRequest.UsePassive = False clsRequest.Proxy = Nothing Dim clsStream As System.IO.Stream = _ clsRequest.GetRequestStream() clsStream.Write(bFile, 0, bFile.Length) ' close stream Log("Closing connection") clsStream.Close() clsStream.Dispose() ' complete Log("Complete") MsgBox("Upload complete") End SubLink to comment
Share on other sites
4 answers to this question
Recommended Posts