views:

330

answers:

3

I need to download some files via ftp from an old AS/400 server. My code looks more or less like:

FtpWebRequest _request = (FtpWebRequest)WebRequest.Create("ftp://ftpaddress/FOO.CSV");
_request.Credentials = new NetworkCredential(_ftpUsername, _ftpPassword);
_request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)_request.GetResponse();

However, an exception is being thrown with the message:

501 Character (/) not allowed in object name.

I'm guessing the AS400 uses a different path separator than / but I can't figure out how to phrase the uri in a way (1) FtpWebRequest accepts and (2) the AS400 understands.

Anyone else bumped into this?

+2  A: 

According to this page, fwd slash is the path separator character:

The forward slash is the separator character for paths sent to the FTP server.

A similar conversation over at Microsoft's forums (2005 era) indicates it's a bug in FtpWebRequest:

Currently FtpWebRequest does not support quote and I cannot think of a way you'll be able to overide the method without exposing our code Mariya Atanasova [NCL]MSFT, Moderator, Nov 2005

Try updating to the most recent versions or try a different library; the MS forum thread has several.

J.J.
A: 

I've had this message often in the past, and it meant that I forgot to change the name format.

There are two name formats possible when doing FTP with an AS400, and it can be changed with the FTP command NAMEFMT:

0 is for the library system files (library\filename.member)

1 is for the files in the IFS, where a CSV file would be

By default, it is set to 0.

Change it to 1 and it should work. However I'm not sure how it can be changed with a FtpWebRequest.

Danny T.
A: 

To make life a little bit easier, the FTP server decides what NameFormat you want to use, based on your first command. If you start with "cd /home", then the FTP server does automatically set NAMEFMT to 1 for you.

Indeed, you can change this manually during your session with the remote FTP command NAMEFMT. Please, notice that you don't need the (old) iSeries way. You can address EVERY object on the iSeries with NAMEFMT 1. For example, "get /QSYS.LIB/MYLIBRARY.LIB/MYFILE.FILE/MYMEMBER.MBR" will do the trick for any iSeries database table. Even for multimember files!

robertnl