Import file on network in Batch job

Question Status

Suggested Answer
Freya Tan asked a question on 10 Apr 2013 7:40 PM

Hi,

I have a batch job that will import a file. The import file is saved in a different server (not where the AOS resides). The batch job runs if I just use a directory where the AOS is installed. Also, if I run the class manually (not as batch job) and I use a network directory, I can import the file successfully. 

Any ideas?

Thanks

Reply
Bilal Issa responded on 11 Apr 2013 12:45 AM

Hi,

can you please write the error you are getting?

Regards,

Bilal

Reply
Freya Tan responded on 11 Apr 2013 1:43 AM

I don't get any error. The batch job succeeds. But the problem, it never execute the file in the directory.

Reply
Dominic Lee responded on 11 Apr 2013 1:51 AM

Check the network folder access right, Make sure AOS service account can access the network folder.

Then try again with the network folder setup.

Reply
Bilal Issa responded on 11 Apr 2013 1:57 AM

Hi,

can you please let me know the code you are using?  are you using WinAPISerevr, or something else?

Regards,

Bilal

Reply
Freya Tan responded on 11 Apr 2013 2:06 AM

I'm using System.IO not WinAPIServer.

Reply
Bilal Issa responded on 11 Apr 2013 2:18 AM

so are using the following code?

      filepermission = new FileIOPermission(fileName, 'R');

       interopPermission = new InteropPermission(InteropKind::ClrInterop);

       permissionSet = new Set(Types::Class);

       permissionSet.add(interopPermission);

       permissionSet.add(filepermission);

       CodeAccessPermission::assertMultiple(permissionSet);

        System.IO.File::Move(fileName,newFileName);

       CodeAccessPermission::revertAssert();

Reply
Freya Tan responded on 11 Apr 2013 2:53 PM

I'm getting the file list from the directory first. My method looks like:

// loop all files that fit the required format

   InteropPermission   interopPerm;

   System.Array        files;

   int                 i;

   container           fileList;

   ;

   interopPerm = new InteropPermission(InteropKind::ClrInterop);

   interopPerm.assert();

   files = System.IO.Directory::GetFiles(@_sourceDirectory, #FileExtension);

   for( i=0; i<ClrInterop::getAnyTypeForObject(files.get_Length()); i++ )

   {

       fileList = conins(fileList, conlen(fileList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(i)));

   }

   return fileList;

Then I loop on the container to process each file. I open the file and assign it to a CommaIo. My code looks like:

boolean openFile(Filename   _fileName)

{

   boolean     ret = true;

   ;

   csvFile = null;

   csvFile = new CommaIo(_fileName, #io_read);

   if(!csvFile)

   {

       //Error when opening file

       ret = checkFailed("@SYS69639");

   }

   return ret;

}

Reply
Bilal Issa responded on 14 Apr 2013 4:56 AM

please try to use the follwoing code to get the files list.

   System.IO.DirectoryInfo     directory;

   System.IO.FileInfo[]        files;

   System.IO.FileInfo          file;

   InteropPermission           permission;

   str         fileName;

   counter     filesCount;

   counter     loop;

   container   mathchingFiles;

   ;

   permission  = new InteropPermission(InteropKind::ClrInterop);

   permission.assert();

   directory   = new System.IO.DirectoryInfo(_folderPath);

   files       = directory.GetFiles(_filePattern);

   filesCount  = files.get_Length();

   for (loop = 0; loop < filesCount; loop++)

   {

       file            = files.GetValue(loop);

       fileName        = file.get_FullName();

       mathchingFiles  +=  fileName ;

   }

   CodeAccessPermission::revertAssert();

   return mathchingFiles;

Reply
Shiva Kumar responded on 8 Dec 2016 11:36 AM

Hi  Freya Tan

I'm trying to export my data to CSV via batch processing and facing errors, my code work in client side but not on Batch, Have you got any solution?

Thanks

Reply
Dominic Lee responded on 9 Dec 2016 1:32 AM

Hi Shiva,

When code is running in batch, they are most likely running on server. Make sure the AOS service account has proper folder rights and the path you specified is in UNC network path.

Reply
Suggested Answer
Crispin John Augustine responded on 9 Dec 2016 2:40 AM

Hi Freya,

If your filepath begins with an ip address and then the folder path, (considering the batch server) and the target machine are connected, this should be a fairly straight-forward task.

Regards,

Crispin

Reply
Shiva Kumar responded on 9 Dec 2016 2:49 AM

Hi Dominic Lee,

My code at below line returning the Null value when running in the batch process, where as  when I run it on client working perfectly..

file = new CommaIo(filename,#io_write);

Will CommaIo class run at Server side?

Thank you  

Reply
Suggested Answer
Vilmos Kintera responded on 9 Dec 2016 3:24 AM

CommaIO will run server side, but WinAPI class calls will not (try WinAPIServer or better to use System.IO namespace from .Net). The problem could also be with your filename, since a regular drive letter and folder would be local to your server. Try a UNC network share, where the AX AOS account has Full access permissions both on the folder and the file share.

Reply
Dominic Lee responded on 9 Dec 2016 3:52 AM

If you are using SysOperation framework then it's server side. If you are using Runbase batch framework then it depends.

Nonetheless, try UNC path first, like Crispin and Vilmos also suggesting. :)

Reply
Suggested Answer
Crispin John Augustine responded on 9 Dec 2016 2:40 AM

Hi Freya,

If your filepath begins with an ip address and then the folder path, (considering the batch server) and the target machine are connected, this should be a fairly straight-forward task.

Regards,

Crispin

Reply
Suggested Answer
Vilmos Kintera responded on 9 Dec 2016 3:24 AM

CommaIO will run server side, but WinAPI class calls will not (try WinAPIServer or better to use System.IO namespace from .Net). The problem could also be with your filename, since a regular drive letter and folder would be local to your server. Try a UNC network share, where the AX AOS account has Full access permissions both on the folder and the file share.

Reply