I'm trying to communicate with an AS/400 FTP Server. As a first try I just execute the WebRequestMethods.Ftp.ListDirectory method, which translates to the NLST FTP command. Doing the same accessing a Microsoft FTP Server or a UNIX FTP Server works fin.
This is the code to get the listing:
Dim Uri As System.Uri = New System.Uri(listUrl) Dim listRequest As FtpWebRequest = CType(WebRequest.Create(Uri), FtpWebRequest) listRequest.Credentials = New System.Net.NetworkCredential(User, Password)listRequest.Method = WebRequestMethods.Ftp.ListDirectory listRequest.KeepAlive = False listRequest.UseBinary = False listRequest.UsePassive = False Dim listResponse As FtpWebResponse = CType(listRequest.GetResponse(), FtpWebResponse) Reader = New StreamReader(listResponse.GetResponseStream()) Return reader.ReadToEnd() |
This is a short trace where the error is occurring (see highlighted section):
System.Net Information: 0 : [5116] FtpWebRequest#8707876::.ctor(ftp://192.168.133.2/mak)
System.Net Information: 0 : [5116] FtpWebRequest#8707876::GetResponse(Method=NLST.)
System.Net Information: 0 : [5116] Associating FtpWebRequest#8707876 with FtpControlStream#50927418
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Received response [220-QTCP at 192.168.133.2. 220 Connection will close if idle more than 15 minutes.]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Sending command [USER TESTUSER]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Received response [331 Enter password.]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Sending command [PASS ********]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Received response [230 TESTUSER logged on.]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Received response [501 OPTS unsuccessful; specified subcommand not recognized.]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Sending command [PWD]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Received response [257 "QGPL" is current library.]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Sending command [CWD QGPL/]
System.Net Information: 0 : [5116] FtpControlStream#50927418 - Received response [501 Character (/) not allowed in object name.]
System.Net Information: 0 : [5116] FtpWebRequest#8707876::(Releasing FTP connection#50927418.)
System.Net Error: 0 : [5116] Exception in the FtpWebRequest#8707876::GetResponse - The remote server returned an error: (501) Syntax error in parameters or arguments.
System.Net Error: 0 : [5116] at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetResponse()
The AS/400 FTP Server dose not allow a "/" for changing directories. The server would accept an alternative filenameformat (quote site namefmt 1) which would accept slashes.
Is there a write method that I could override to filter the CWD command and change it
Or is there a way to insert the "site namefmt 1" command
I hope someone can help me with this problem!

FtpWebRequest - Access to IBM AS/400 FTP Server - 501 Character (/) not allowed in object name.
Suresh K
Alexey Lavnikov
I am dumbfounded that Microsoft let this slide! Entire classes of FTP servers can't be accessed all because of a path separator!! Microsoft, an easy fix to this would be to expose a path separator property on the FtpWebRequest class, that way people whose server doesn't support a / as the path separator can specify what it is. That, or don't insist on appending a slash to the end of the path.
When a simple program like ftp that's been built into the OS for years can do something that complex .NET can't do it's a shame, especially when the only problem is a slash character... The quality of Microsoft products is going down, erm, getting even worse.
Kathirvel
As you can see from Mariya’s message (28.09.2006) FtpWebRequest dose still not support the special directory and file structure of AS/400.
As a workaround I start FTP.EXE in a separate process. It is not the nicest way to do the work but it works. Of course it dose not support any secure transport but as I work over VPN it is not necessary.
This is an example how to retrieve files from the FTP-Server:
keenan10000
Has anything changed regarding this behavior since the last post (11-30-2005)
Has Microsoft come up with any workarounds, so that we can connect to AS/400, VMS & MVS FTP servers using .Net
Esprite2000
Unfortunately your scenario is still not supported for FtpWebRequest. We will work on getting this fixed in a future release
Mariya
Julius Rastad
_Alen_
I will look into this.
Is this server reacheable over the internet
CristianC
Lachezar Georgiev
Chekib
ffe_bob
Katie,
I came to a complete deadend with Microsoft on this. Simply not supported and no workarounds.
I'm currently converting my code over to using WeOnlyDo - wodFtpDLX.NET component.
It's relatively inexpensive and was the only 3rd party component that I could find to handle the SSH protocol in addition to all the variations of SSL.
I am currently working with the developers of this software, so that their component correctly parses directory stuctures for AS/400, MVS & VMS.
Since I already had the parsing logic in my program, I kept it in as a precautionary fail-over. The main thing I was after anyway, was for the component to handle making the connections via the correct protocol.
Here's a link if you want to check into this software to see if it meets your needs.
http://www.weonlydo.com/index.asp showform=FtpDLX.NET
Hopefully this will save you some time and frustration.
Good Luck, Dave
Mark Chad
Mark Guinness
Thanks for the update... I've been trying to do the same thing and running into this error. Thanks for the helpful information.
FYI, we've use the Xceed .NET FTP component to access the AS400 programmatically. Its fully featured, but its not cheap.
http://www.xceedsoft.com/products/FtpNet/index.aspx
bw_123