× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Can anyone verify that when FTP'ing an IFS file that is still being created
through another FTP, the file to FTP will either be complete or not there?
Would you only FTP part of the file?  I haven't been able to perform a good
test.

Rick,
Thanks for the info.  Unfortunately, it appears that fcntl() would not
really ensure that the file has been FTP'ed completely since I use open()
to get a file descriptor for fcntl() and the lock information would
probably be on my open().  I even tried open() with O_SHARE_RDONLY and that
opened without errors when I was trying to test by opening at the same time
as FTP'ing.  It also appears that we may be the first ones to actually try
using fcntl() for files rather than sockets and I never got it to work.  It
looks like access() might be the winner.  I have code now in a job that
will eventually run every morning to do an access(), FTP, and unlink().
So, I do access() to see If the IFS file exists, I FTP the file (and submit
the call to process the file on the other AS/400) and unlink() (delete) the
IFS file on the current AS/400.  Doing access() with F_OK (file exists?)
would tell us if the file exists.  There is also a W_OK (write permission?)
you can use too.  I did extensive testing with W_OK and some with F_OK by
doing the access at the same time as the FTP and the only error I ever got
was a 3025 (file not there).  It appears that once the file is there, you
may not be able to tell if it is complete yet but the file I tested with
only took a few seconds anyway.

If we receive small files (and you can test to see how long it takes to
FTP), you might just FTP whatever is there.  This is what I am planning on
doing since I couldn't break it with tests.
I am now thinking that if we receive large files that take awhile and we
don't know when they will come, we should either:
1. Ask them to write another file meaning the file is now complete.
or
2. After doing an access() and you see the file exists, wait a certain
period of time to better ensure the file is complete before FTP'ing.
or
3. If anyone can get access() or some other API to show locks that I could
not test or get to work, use that and if locked, look again later before
the FTP.
Maybe partial files are not an issue and the file appears all at once.  I
don't think I have to deal with this yet though.  It would be good to know
for the future.

Now for a little code that might help you:

      * IFS variables
     D fn              S            512A   Varying
File name
     D rc              S             10I 0
Return code
     D p_errno         S               *
     D errno           S             10I 0 Based(p_errno)

      * access() constants
     D R_OK            S             10I 0 INZ(4)
Read permission?
     D W_OK            S             10I 0 INZ(2)
Write permission?
     D X_OK            S             10I 0 INZ(1)
Execute permission?
     D F_OK            S             10I 0 INZ(0)
File exists?

      * Determine IFS file accessibility
     D access          PR            10I 0 ExtProc('access')
     D  path                           *   Value Options(*String)
     D  amode                        10I 0 Value

      * Delete an IFS file
     D unlink          PR            10I 0 ExtProc('unlink')
     D  path                           *   Value Options(*String)

      * Error number
     D errnof          PR              *   ExtProc('__errno')

      * ================ Begin Calculation Specifications ============
     C                   Eval      fn = '/hmup/craigsdem.demand'

     C                   ExSr      MoveFile

     C                   Eval      *InLR = *On
     C                   Return

      *****************************************************************
      * Move file
      *****************************************************************
     C     MoveFile      BegSr
      * Ensure file exists
     C                   Eval      rc = access(fn:F_OK)
     C                   If        rc <> 0
     C                   Eval      p_errno = errnof
     C                   LeaveSr
     C                   EndIf

      * FTP code goes here and make sure you do a LeaveSr if there is an
FTP error.

      * Delete IFS file
     C                   Eval      rc = unlink(fn)
     C                   EndSr
MoveFile

      * ================ End Calculation Specifications ==============

Thanks,
Craig

*** Rick wrote:
Craig,

after further review of the archives, I ran across a link to Scott
Klement's website which has an example of using fcntl() - albeit for
sockets rather than files, but I think it might help.

http://klement.dstorm.net/rpg/socktut/tutorial.html

scan for fcntl.

hth,

Rick

--my original message---
Craig,

I noticed that no one has answered your post.  Have you gotten fcntl() to
work yet?  I'm currently trying to do the same.

I too, would love to see a working code snippet.



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.