We help IT Professionals succeed at work.

Copy of text files to AS/400

arturosm
arturosm used Ask the Experts™
on
Hello Experts.

I'm trying to copy some text files from a Windows Server 2008 to a shared folder that resides in AS/400. This is for a client of mine, I don´t know what they are using to share the folder nor know about their AS/400 release.

I can copy the files using the Windows command prompt (MS-DOS like) and using the File Explorer. I also tested with a .bat file to do the copy and it works well.

However if I try to do the copy from a simple Delphi application the file is not copied, even if I call the .bat file, the file is not copied. If I copy the file to a Windows folder (not AS/400), from the same application, the file is copied correctly in the local server or to a shared network folder.

How this AS/400 folder "knows" that I'm copyng the file from an application or what could be the problem?

Regards.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is a bit of a stretch, but if your DELPHI "application" is a WEB application, the copy is being attempted by the WEB app user, not your user and it is a file permissions problem.

Is it a web app?  Does the DELPHI app run AS YOU?

Author

Commented:
Hi SeanDevoy:

The delphi is a win32 application and the Windows server is also 32 bits. I run it as administrator, I don´t know how to link the user connected to the AS/400 shared folder with the user running the windows application.

Regards.
VP Technology / Senior Consultant
Commented:
When you successfully copy using the command line:

From what specific machine?
Can you give us the exact command that works? (mapped drive or URI?)
What Windows user are you logged on as when doing this?

When your Delphi app fails:

From what specific machine?
What error message do you receive?

You say that you are logged on as "administrator".  The windows "administrator" (domain or local) means nothing special to the AS/400 netserver.  Netserver takes the first 10 characters of the Windows user profile name and tries to match it to an AS/400 user name.  If it finds a match and the passwords also match, access to the share is granted.  If not, the user is prompted to enter a valid AS/400 user ID and password.

Note that Netserver CAN also be configured with a guest AS/400 profile to use when the Windows profile does not match an AS/400 profile.

The AS/400 neither "knows" nor cares that you are copying from an application.  If your application runs as a service, or spawns a shell to run the BAT file that does not interact with the desktop, it is possible that that there is a hidden password prompt that is causing problems.  IF that is the case, you'll need to make sure that they have a guest profile configured in Netserver, or that you use a Windows profile that matches an AS/400 profile that has rights to the share.

Also, if your application refers to a mapped drive letter, it is possible that the drive letter mapping is not visible to your application.  Use a URI instead:

i:\myfile.pdf   <- Depends on a mapped drive
\\myAs400\myshare\myfile.pdf  <- Does not.  Much better practice.

Hope that helps.

- Gary Patterson




Author

Commented:
Hi Gary_The_IT_Pro:

All the tests are done from the windos server machine, I have been told the user of windows has nothing to do with the AS/400 user. The windows user is "Administrator" and the AS/400 is "test400\rtest1".  

The commands that works are (examples):

s:\myfile.pdf  
\\myAs400\myshare\myfile.pdf   (using the IP of the machine not he name)

I have tried both and the call to the bat file but neither works.

For the copy I'm using the API function Windows.CopyFile, the program runs form the server also.

Thank you for your help.



Gary PattersonVP Technology / Senior Consultant

Commented:
What is the error?

- Gary Patterson

Author

Commented:
Hi Gary_The_IT_Pro:

No error, the CopyFile function just returns false which means the file was not copied. I send the output of the .bat file and the file shows "0 files copied". But no errors or exceptions. The file to be copied does not exists in the AS400.

Regards.

Author

Commented:
Ok, I used the GetLastError to obtain the code it is: Access is denied.

Will check with the IT guys to set up the users correctly.


Thanks Gary.
I am very intrested in "I run it as administrator" ...
Clearly this apears to be a "permisions" issue.  If you MAP a Drive or just use network access to get to the share, that is "authenticating" through the netwrok as YOUR USERID.  if you run as Administrator, it is deffinitely not.  You will have to grant the access appropriate to Administrator.

What happens if you just run it as YOU?

Sean
Gary PattersonVP Technology / Senior Consultant

Commented:
No problem.  "Run As Administrator" is meaningless to the AS/400.  All this does is elevate your Windows session to run using local admin rights when running on a machine using User Access Control.  All the AS/400 cares about is if the NAME and PASSWORD of the Windows profile matches the NAME and PASSWORD of an AS/400 profile.

IF it does, and the AS/400 profile has rights to the AS/400 file and folder, then your copy will succeed.  If not, it won't.

Again, it is possible, but not required for the AS/400 administrator to set up a guest NetServer profile, but if that was the case, you wouldn't be getting errors (unless the guest profile wasn't authorized to this particular folder, of course.)

So, if you'll just make sure your program is running under a Windows profile that can perform the copy manually, the copy should succeed.

- Gary Patterson

The AS/400 can't allow just any user on just any remote system to read/write files on it. Authentication into the AS/400 must be done in order to allow access. By default, the only credentials that Windows will send are for the user ID of the process, to which the AS/400 is likely going to respond "Sorry, no one is registered by that name."

Gary has pretty much covered the issue.

Note that IF you have a .BAT file, you might want to put a NET USE command into it to pass credentials (i.e., user and password) over to your AS/400 for the shared directory. The user/password that you would use should be one that is created on the AS/400 with very restricted rights, just enough to transfer the data, since it will be exposed in the .BAT file.

Alternatively, you might look into kerberos and Active Directory and the way your Windows authentication/authorization is done. You can kerberize many of your AS/400 server apps so that interaction with Windows networking can allow your Windows network credentials to authenticate you to an AS/400 profile. You probably don't want that done for "Administrator" though, and something like NET USE will probably get you working sooner.

Tom

Commented:
It you are using a shared folder in the IFS, the AS400 user that is configured in the PC with the net use command, must also be configured in WRKDIRE

Author

Commented:
Thank you Experts.

This was about permisions, once I ran the program as the user logged in to the server, not the administrator, it worked well.