By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,240 Members | 791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,240 IT Pros & Developers. It's quick & easy.

Error uploading e file with FtpWebRequest

P: n/a
Hello,

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())
oStream.Close()

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),
FtpWebRequest)

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile

ftpRequest.ContentLength = arBytes.Length

ftpRequest.Credentials = New NetworkCredential(mstrRemoteUser,
mstrRemotePassword)

Dim oftpStream As Stream

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

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

Dim ftpResponse As FtpWebResponse
ftpResponse = ftpRequest.GetResponse

s = ftpResponse.StatusDescription

Return s
Feb 21 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.