I searched for all the posts and tried the methods suggested there but no success, I still get the "The requested URI is invalid for this FTP command" error.
Here is what I try to do:
I am writing an application in VS.net 2005 to generate a file from the database, and later on I am going to upload this file to a remote server. Here is my code to upload to a remote server:
Private
Sub uploadFile()
Dim ftp As FtpWebRequest =
CType(FtpWebRequest.Create("ftp://remoteserver.com/foldername/"), FtpWebRequest)
ftp.Credentials = New NetworkCredential("username",
"password")
ftp.KeepAlive =
False
ftp.UseBinary =
True
ftp.Proxy =
Nothing
ftp.UsePassive =
False
ftp.Method = WebRequestMethods.Ftp.UploadFile
Dim objStream
As New FileStream("C:\Textfile\ThisText.txt", FileMode.Open)
Dim buffer(objStream.Length)
As Byte
objStream.Read(buffer, 0, objStream.Length)
objStream.Close()
objStream =
Nothing
Dim GetStream
As Stream = ftp.GetRequestStream()
GetStream.Write(buffer, 0, objStream.Length)
GetStream.Close()
ftp =
Nothing
End Sub
Is there something wrong in my code? Thanks a lot for the help!!!
ey40
0 Points
3 Posts
The requested URI is invalid for this FTP command
Mar 13, 2008 05:47 PM|LINK
Hi,
I searched for all the posts and tried the methods suggested there but no success, I still get the "The requested URI is invalid for this FTP command" error.
Here is what I try to do:
I am writing an application in VS.net 2005 to generate a file from the database, and later on I am going to upload this file to a remote server. Here is my code to upload to a remote server:
Private Sub uploadFile() Dim ftp As FtpWebRequest = CType(FtpWebRequest.Create("ftp://remoteserver.com/foldername/"), FtpWebRequest) ftp.Credentials = New NetworkCredential("username", "password")ftp.KeepAlive =
Falseftp.UseBinary =
Trueftp.Proxy =
Nothingftp.UsePassive =
Falseftp.Method = WebRequestMethods.Ftp.UploadFile
Dim objStream As New FileStream("C:\Textfile\ThisText.txt", FileMode.Open) Dim buffer(objStream.Length) As ByteobjStream.Read(buffer, 0, objStream.Length)
objStream.Close()
objStream =
Nothing Dim GetStream As Stream = ftp.GetRequestStream()GetStream.Write(buffer, 0, objStream.Length)
GetStream.Close()
ftp =
Nothing End SubIs there something wrong in my code? Thanks a lot for the help!!!
ey40
0 Points
3 Posts
Re: The requested URI is invalid for this FTP command
Mar 18, 2008 02:28 PM|LINK
Can anyone help me on this? Thanks!
anphme
Member
622 Points
81 Posts
Re: The requested URI is invalid for this FTP command
Mar 18, 2008 03:41 PM|LINK
According to http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1290688&SiteID=1&pageid=0#1291001 you need to specify the file name in your uri so that the server knows where to write it.
Also, after the statement GetStream.Close(), you need to use:
Dim response As FtpWebResponse = CType(ftp.GetResponse(), FtpWebResponse);
This will send your request to the FTP Server. You can then use response.Status and response.StatusDescription to see what happened.
Hope this helps.
ey40
0 Points
3 Posts
Re: The requested URI is invalid for this FTP command
Mar 19, 2008 02:30 PM|LINK
Thanks a lot anphme, everything is working fine now.