473,395 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Error uploading e file with FtpWebRequest

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
0 2743

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dawson | last post by:
Hello, when running the code below, it returns the error message: "The requested URI is invalid for this FTP command.". I have confirmed the FTP URI is correct and working through a standalone...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
5
by: Sendil kumar | last post by:
Hi All, The FtpWebRequest.GetResponse( ) method is not giving "550 File not found exception " when I do a directory list operation on a invalid(not present) directory in HP Unix and Sun Solaris...
2
by: Bremanand | last post by:
Hi folks, i am working in C# , i have problem while uploading the file to FTP which has size around 4MB. The code which comes after the bold area is not executed.. here am...
3
by: Bremanand | last post by:
Hi folks, i am working in C# , i have problem while uploading the file to FTP which has size around 4MB. The code which comes after the bold area is not executed.. here am interacting with DB for...
0
by: pavya | last post by:
Hi All, I am working on FTP uitility using C#. I have build a class for that using C#. But while uploading the file on FTP i am unable to upload whole file on the FTP. Only part of that file is...
0
by: jason7069 | last post by:
Hi There. I recently implemented a FTP upload feature within an ASP.NET application. I use the standard steps that are posted throughout the web. The basic funcationality works as a file is...
5
by: TC | last post by:
Hey All, I'm trying to upload files via FTP and I'm using FtpWebRequest and WebClient. Unfortunately, I'm receiving a "Not Logged In" error. I know that others have seen this as I've seen...
0
by: =?Utf-8?B?Qm9i?= | last post by:
I have written a Windows service that periodically lists the contents of an FTP directory until a new file becomes available. Then, it gets the new file and writes it to the local server. Most of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.