Webexception Error FTP 501

G

Guest

Hi everyone,

I am trying to get the WebRequestMethods.Ftp.DownloadFile working using the
101 Samples for the Base Class Library from MS. I can get through the
authentication part OK but when the code gets to:

Dim ftpResponse As FtpWebResponse = CType(ftpRequest.GetResponse,
FtpWebResponse)

I receive a Webexception error of "The remote server returned an error:
(501) Syntax error in parameters or arguments. I searched around a bit but
didn't find anything more specific on the 501 error.

I am fairly new to VB 2005 (moving on from VB6) but I have used the
wininet.dll (InternetOpen, InternetConnect, FtpGetFile) to do the same ftp
download in VB6. I didn't really want to use that again since the framework
2.0 has the ftp functions.

Also the server that I ftp to is an AS/400 system, but I really don't
remember having to do anything special with the code I used in VB6. I was
hoping that the issue is just a learning curve problem for me!

Thanks for your help!
Randy
 
K

Kevin Spencer

The 501 error means there is a syntax error in parameters or arguments.

Many FTP commands include parameters. STOR, for example, requires a path
parameter indicating the path and file name on the server to save the
uploaded file to. There was something wrong with your parameter.

For future reference, here's my favorite FTP reference:
http://cr.yp.to/ftp.html

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
A

Ashish Jindal

Hi,

If you are looking for a full C# FTP library, you may contact EduJini
Team. I know, for sure, they have a C# library as well as a simple GUI (not
with many advanced features) using WinForms.

You may contact (e-mail address removed)

Website: http://www.edujini.in (I think they are revamping it.)

-Ashish
 
G

Guest

Thank you both for your replies. Unfortunately I do not know which parameter
is throwing the 501 error since the parameters I am using for the RETR
command (using the WebRequestMethods.Ftp.DownloadFile) are the same strings I
use for the VB6 wininet.dll stuff. Is there anyway to look inside the request
to see which line or command the process is failing at?

Thanks - Randy
 
K

Kevin Spencer

You're not giving us much to go on here. While you know what "the parameters
I am using for the RETR command" are, you still haven't told us.

In fact, the file to download must be part of the RequestUri that you create
when creating the FtpWebRequest. and are you using one of the
WebRequestMethods.Ftp enumeration values? If not, what *are* you doing?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
G

Gaurav Vaish \(EduJini.IN\)

is throwing the 501 error since the parameters I am using for the RETR
command (using the WebRequestMethods.Ftp.DownloadFile) are the same
strings I
use for the VB6 wininet.dll stuff. Is there anyway to look inside the
request

1. Are you trying to create a FTP client library?
2. Do you need a managed FTP client library?

In case of (1), don't use WebRequest. You Sockets directly. They will be
better.
In case of (2), you can drop me a mail at info[at]edujini[dot]in for the
library and/or source code. We have a fully featured FTP library written in
C#
 
K

Kevin Spencer

I also built a managed FTP client library using Sockets. I found the
FtpWebRequest to be problematic when used for anything but the simplest
commands. It hides too much information, making it difficult to debug. In
addition, I found the programming interface counter-intuitive, as it was
designed to behave in the same way as the HttpWebRequest, which encapsulates
an entirely different sort of protocol. HTTP is a protocol which is used for
atomic Request/Response operations, and uses a single port and TCP
connection, while FTP maintains an open connection for the Control, and
opens a separate connection to send and receive Data. I felt that the
decision to make the 2 programming interfaces similar was a mistake, and
violated good OOP principles, which dictate that the object model should
resemble the actual underlying technology. In this case, it resembles HTTP
rather than FTP, and is therefore counter-intuitive, as well as hiding
(without remedy) what is going on underneath, except for the Response codes
and status messages. That is not a problem when everything goes well, but
FTP is not nearly as reliable as HTTP, and when something goes wrong, you
need to look under the hood to find out why. Network tracing only provides a
modicum of information, which is helpful in some respects, but doesn't
provide any information about the actual data sent and received over the
Socket.

In my case, I was trying to diagnose an intermittent "Client Closed
Connection" error, which it turns out was caused by a clustered FTP server
requiring a specific client IP address to connect, and for which only one of
the machines was configured to accept our IP address. I only found this out
by some rather deep probing using a Socket-based class (with the help of
Ethereal).

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Gaurav Vaish (EduJini.IN) said:
is throwing the 501 error since the parameters I am using for the RETR
command (using the WebRequestMethods.Ftp.DownloadFile) are the same
strings I
use for the VB6 wininet.dll stuff. Is there anyway to look inside the
request

1. Are you trying to create a FTP client library?
2. Do you need a managed FTP client library?

In case of (1), don't use WebRequest. You Sockets directly. They will be
better.
In case of (2), you can drop me a mail at info[at]edujini[dot]in for the
library and/or source code. We have a fully featured FTP library written
in C#
 
G

Gaurav Vaish \(EduJini.IN\)

Hi Kevin,
I also built a managed FTP client library using Sockets. I found the
the machines was configured to accept our IP address. I only found this
out by some rather deep probing using a Socket-based class (with the help
of Ethereal).

Great to hear that. The recipe (of Sockets) worked! May be you can also
make a robust FTP client by adding a lot of events to it (not sure if you
already have it)... say when a user is connected / discon / command is sent
/ response received etc...


--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top