469,627 Members | 1,090 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

Error uploading e file with FtpWebRequest


I am trying to upload a file to an ftp server using the FtpWebRequest class,
but I get the following error.
The requested URI is invalid for this FTP command.

I do can upload the file from the Internet Explorer so I have rights to do
it. Why is the 2.0 FtpWebRequest class failing? What I am doing wrong?

My Code:
Dim ftpUri As Uri
Dim s As String

Dim oStream As New StreamReader(mstrFileName)
Dim arBytes() As Byte = Encoding.UTF8.GetBytes(oStream.ReadToEnd())

ftpUri = New Uri(mstrRemoteHost)

If Not (ftpUri.Scheme = Uri.UriSchemeFtp) Then
Throw New ArgumentException("URI is not an FTp site")
End If

Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(ftpUri),

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile

ftpRequest.ContentLength = arBytes.Length

ftpRequest.Credentials = New NetworkCredential(mstrRemoteUser,

Dim oftpStream As Stream

oftpStream = ftpRequest.GetRequestStream()
Catch ex As Exception
Return ex.Message
End Try

oftpStream.Write(arBytes, 0, arBytes.Length)

Dim ftpResponse As FtpWebResponse
ftpResponse = ftpRequest.GetResponse

s = ftpResponse.StatusDescription

Return s
Feb 21 '06 #1
0 2578

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by dawson | last post: by
reply views Thread by Buddy Home | last post: by
reply views Thread by =?Utf-8?B?Qm9i?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.