C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-24-2009, 01:53 PM   #16
pwning noobs
 
Zlatko's Avatar
 
Join Date: Jun 2009
Location: The Great White North
Posts: 125
The d_ino is not the inode of the file. I suppose d_ino is the inode of the link in the fd directory.
Zlatko is offline   Reply With Quote
Old 06-24-2009, 02:10 PM   #17
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
Quote:
Originally Posted by IsmAvatar2 View Post
brewbuck: The program that is depositing the files is ftp. If you want to say FTP is broken, be my guest.
I think the way you should take this then is to consider the way in which you are using ftp. You could write a shell script to do exactly what brewbuck is talking about (download the file to a tmp directory and when complete, transfer the file locally to the permanent directory); that would save you these problems.

Of course, that sounds like exactly what you are trying to do. I'm going to guess you are just running ftp with a list of files. If so, take a few steps back to consider the nature of the problem. You should be calling ftp within your C program (or shell script); this way you can wait for it to complete a file, then transfer it.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Old 06-24-2009, 02:50 PM   #18
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Quote:
Originally Posted by IsmAvatar2 View Post
itCbitC: In order to better test your idea, I created 2 processes.
The first one opens a file for writing, waits 5 seconds, and then closes it and terminates.
The second one simply attempts to put a write lock on the same file (as per your code), and reports the return value and any changes to the struct.

I ran the first one, and during those 5 seconds, I ran the second one. The second one reports return value 0 (lock granted) and no change to the structure (mode: 1, everything else is 0).
Unless I'm mistaken, this confirms that the file may be opened for writing without having a write lock on it, which further confirms that I need another way to detect if the file is opened for writing or not.
This isn't the first time fcntl() has me stumped but I didn't realize it would be going "against-the-grain" so much. The code I have contradicts everything in the man pages. I duplicated your test too and got the same results. I am off to trying something else and in the meantime perhaps someone else might be able to shed some light on this mystery.
itCbitC is offline   Reply With Quote
Old 06-24-2009, 03:02 PM   #19
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by IsmAvatar2 View Post
brewbuck: The program that is depositing the files is ftp. If you want to say FTP is broken, be my guest.
FTP isn't broken, but this particular way of using it obviously is.

Is it an FTP client or an FTP server which is depositing the files? If a client, then you can script the activity to move the complete file to the target directory after the download is complete.

If it's a server, then your server is braindead. It's an extremely common task to monitor an FTP upload area for new files. Any FTP server that isn't completely stupid has a way of downloading files to a temporary area then MOVING them to their final location when the download is complete. Exactly because of this issue.

Even better servers give you the ability to run a trigger when a file has been completely uploaded.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 06-24-2009, 08:17 PM   #20
Registered User
 
Join Date: Jan 2007
Posts: 40
brewbuck: I'm not sure what you mean.
I have an FTP server which is set to *receive* files. Various people will ftp in and upload a file to the server. It is then the server's responsibility to forward these files (when they are complete) to another computer (which is what my program will do, and that code is no problem). The problem is, I don't know when the files are done being uploaded from the various clients except presumably when the files are closed and ftp is no longer accessing them.
I have no control over what the client does to ftp in the file, so they're most likely to just upload the file directly, rather than uploading it to a temp location and then moving it.
If there's anything the FTP server can do to assist, I'm not sure how to utilize it. As it stands, I look in the directory where the files are coming in, and I see the files created at 0 bytes, and then watch them increase in size as the data transmits through ftp, until the transfer completes. As far as I'm aware, no file movement is happening.
IsmAvatar2 is offline   Reply With Quote
Old 06-24-2009, 08:34 PM   #21
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
Quote:
Originally Posted by IsmAvatar2 View Post
If there's anything the FTP server can do to assist, I'm not sure how to utilize it.
There has got to be a way there, even if you don't know about it. There is no such thing as software that dysfunctional. You're talking about a very simple and commonplace task. Why don't you say specifically which ftp server you are using?
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Old 06-24-2009, 10:19 PM   #22
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Quote:
Originally Posted by IsmAvatar2 View Post
brewbuck: I'm not sure what you mean.
I have an FTP server which is set to *receive* files. Various people will ftp in and upload a file to the server. It is then the server's responsibility to forward these files (when they are complete) to another computer (which is what my program will do, and that code is no problem). The problem is, I don't know when the files are done being uploaded from the various clients except presumably when the files are closed and ftp is no longer accessing them.
I have no control over what the client does to ftp in the file, so they're most likely to just upload the file directly, rather than uploading it to a temp location and then moving it.
If there's anything the FTP server can do to assist, I'm not sure how to utilize it. As it stands, I look in the directory where the files are coming in, and I see the files created at 0 bytes, and then watch them increase in size as the data transmits through ftp, until the transfer completes. As far as I'm aware, no file movement is happening.
That being the case I don't see why you need a programmatic solution when a scripted one will do just fine.
Use a shell to script this process and run fuser on the file periodically to see if ftp is done transferring it.
Incidentally fuser is a simple maintenance command instead of a syscall or a stdlib.
Code:
man fuser
BTW which one of the Unixes are you on?
itCbitC is offline   Reply With Quote
Old 06-25-2009, 03:25 PM   #23
Registered User
 
Join Date: Jan 2007
Posts: 40
vsftpd and Debian.
IsmAvatar2 is offline   Reply With Quote
Reply

Tags
file, fuser, lock, lsof, open

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C Delete opened file gidion C Programming 25 12-04-2008 10:35 AM
Formatting a text file... dagorsul C Programming 12 05-02-2008 03:53 AM
Need Help Fixing My C Program. Deals with File I/O Matus C Programming 7 04-29-2008 07:51 PM
spell check in C using a dictionary file goron350 C Programming 10 11-25-2004 06:44 PM
C programming with Unix functions for manipulation of a virtual file system zagelle C Programming 4 10-21-2003 04:28 PM


All times are GMT -6. The time now is 08:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22