Arokh
Well-known member
- Joined
- Apr 11, 2006
- Messages
- 124
Upload File via FTP (URI is invalid for this FTP command)
I just wanted to upload a file to a WebServer (on which I have full access) with my program,
I didnt expect it would be so bothersome.
I finally decided to use FTP for this action, but I have run into some problems:
Im using the example from http://msdn2.microsoft.com/en-us/library/ms229715.aspx
Converted into VB.NET
[VB]
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
...
Dim FTPCon As FtpWebRequest
FTPCon = WebRequest.Create("ftp://[HOST]:2100")
FTPCon.Method = WebRequestMethods.Ftp.UploadFile
FTPCon.Credentials = New NetworkCredential("[USERNAME]", "[PASSWORD]")
Dim FileContent() As Byte = Encoding.Unicode.GetBytes("Test.txt")
FTPCon.ContentLength = FileContent.Length
Dim ReqStream As Stream = FTPCon.GetRequestStream
ReqStream.Write(FileContent, 0, FileContent.Length)
ReqStream.Close()
Dim FTPRes As FtpWebResponse = FTPCon.GetResponse
If FTPRes.StatusCode = FtpStatusCode.FileActionOK Then
Return True
Else
Return False
End If[/VB]
But as soon as the program reaches FTPCon.GetRequestStream it throws the error:
A first chance exception of type System.Net.WebException occurred in System.dll
The requested URI is invalid for this FTP command.
Ive checked if the FTP Server is running with a FTP Client and there it works fine.
EDIT:
The WebServer is within my LAN, I dont know if thats important.
I just wanted to upload a file to a WebServer (on which I have full access) with my program,
I didnt expect it would be so bothersome.
I finally decided to use FTP for this action, but I have run into some problems:
Im using the example from http://msdn2.microsoft.com/en-us/library/ms229715.aspx
Converted into VB.NET
[VB]
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
...
Dim FTPCon As FtpWebRequest
FTPCon = WebRequest.Create("ftp://[HOST]:2100")
FTPCon.Method = WebRequestMethods.Ftp.UploadFile
FTPCon.Credentials = New NetworkCredential("[USERNAME]", "[PASSWORD]")
Dim FileContent() As Byte = Encoding.Unicode.GetBytes("Test.txt")
FTPCon.ContentLength = FileContent.Length
Dim ReqStream As Stream = FTPCon.GetRequestStream
ReqStream.Write(FileContent, 0, FileContent.Length)
ReqStream.Close()
Dim FTPRes As FtpWebResponse = FTPCon.GetResponse
If FTPRes.StatusCode = FtpStatusCode.FileActionOK Then
Return True
Else
Return False
End If[/VB]
But as soon as the program reaches FTPCon.GetRequestStream it throws the error:
A first chance exception of type System.Net.WebException occurred in System.dll
The requested URI is invalid for this FTP command.
Ive checked if the FTP Server is running with a FTP Client and there it works fine.
EDIT:
The WebServer is within my LAN, I dont know if thats important.
Last edited by a moderator: