FtpWebRequest Connecting to AS / 400

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

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 thrown with the message:

 501 Character (/) not allowed in object name. 

I assume that AS400 uses a different path separator than /, but I can’t figure out how to correctly calculate uri (1) accepts FtpWebRequest and (2) understands AS400.

Has anyone else come across this?

+1
source share
5 answers

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

A slash is a delimiter character for paths sent to the FTP server.

A similar conversation on Microsoft forums (2005 era) indicates an error in FtpWebRequest:

Currently FtpWebRequest does not support quoting, and I can’t think about how you can redefine the method without exposing our code Maria Atanasova [NCL] MSFT, Moderator, November 2005

Try upgrading to the latest versions or try another library; There are several in the MS forum forum.

+2
source

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

When running FTP with AS400, two name formats are possible and can be changed using the FTP NAMEFMT command:

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

1 for files in IFS, where the CSV file will be

The default value is 0.

Change it to 1 and it should work. However, I'm not sure how this can be changed using FtpWebRequest.

+2
source

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

Indeed, you can change this manually during a session using the remote NAMEFMT FTP command. Please note that you do not need the (old) iSeries method. You can address EVERY object on iSeries using NAMEFMT 1. For example, "get / QSYS.LIB / MYLIBRARY.LIB / MYFILE.FILE / MYMEMBER.MBR" will do the trick for any iSeries database table. Even for files with multiple files!

0
source

I still have the same problem when I try to upload a file to AS400, but this page will be useful for you:

http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/b4b2e05c-625b-466b-9a11-6173f17187b4/

0
source

This is a general answer from previously provided, but I was able to get this working using the following structure:

ftp: // [HostName] /% 2F / [directory] / [subdirectory] / [filename] .csv

Requires "% 2F" and serves as a separator between the host name and the path.

0
source

Source: https://habr.com/ru/post/1308902/


All Articles