LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   lsof permission (https://www.linuxquestions.org/questions/programming-9/lsof-permission-602373/)

champak 11-26-2007 12:29 AM

lsof permission
 
Hi..
This is related to the question http://www.linuxquestions.org/questi...ogress-600769/

Im using lsof to track a file transfer.Im moving the file that is completely FTP transfered.
If I use "su" and then execute lsof, Im able to see the file transfer and abort the "mv"..
But as a user I cldn find in lsof, the file under FTP transfer.
Is there any way the user can be added to see the FTP transfered file in lsof?

Thanks,
Ananth

matthewg42 11-26-2007 12:51 AM

Why not just use the "hash" command in the FTP session to track the progress? Or send using some tool which displays progress somehow...

champak 11-26-2007 01:49 AM

The problem is I dont have the control over the ftp session. My script (automated scripts,supposed to do the tasks described above) resides in the site receiving the tranfered files. So the script has to identify the completely transfered files before moving them.

bigearsbilly 11-26-2007 02:36 AM

what are you trying to do?

it very very difficult to keep track of ftp sessions and the like.
I wouldn't try if you want an easy life.

why not send a list of the files and their cksums, first of all,
these can then be double checked on receipt.

matthewg42 11-26-2007 02:57 AM

I see. Incidentally, how are you monitoring the progress using lsof as root, and what version of lsof / the OS are you using?

For files coming to your machine, you can simply look to see the size of the incoming file, so I assume it is the other way round, and that you do not have access to the remote machine to look and see how much of the file has arrived there....

There is a way, assuming the ftp client is not doing anything fancy with the file (like opening multiple connections and sending more than one part of the file at once). The vanilla ftp client which comes with most distros should be fine with the following method.

In the /proc filesystem, you will see a directory which corresponds to your ftp client process. To find the process ID, do something like this:
Code:

% ps aux |grep ftp
matthew  20917  0.1  0.2  2804  1368 pts/2    S+  08:44  0:00 ftp iggy.local

Here you can see the PID of the ftp client process is 20917. Look in /proc/20917/fd and you will see a list of links to files which the ftp client has open:
Code:

% cd /proc/20917/fd ; ls -l
total 0
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 0 -> /dev/pts/2
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 1 -> /dev/pts/2
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 2 -> /dev/pts/2
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 3 -> socket:[228845]
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 4 -> socket:[228845]
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 5 -> socket:[228845]
lr-x------ 1 matthew matthew 64 2007-11-26 08:44 6 -> /tmp/file_being_put_to_remotehost
lrwx------ 1 matthew matthew 64 2007-11-26 08:44 8 -> socket:[228921]

The file I am putting to the remote host is /tmp/file_being_put_to_remotehost, which corresponds to file handle number 6.

In the /proc/20917/fdinfo directory there is also a file called 6. If I cat this file, I get this sort of thing:
Code:

cat /proc/20917/fdinfo/6
pos:    14991360
flags:  0100000

I assume the pos is the current offset in the file which is being read. When I run the cat command again, I see the value incremented by an amount which seems consistent with the idea that this is tracking how far through the file the reading is. This should give some indication of how far through the file you are.


All times are GMT -5. The time now is 09:36 AM.