How do I view the job queue in lftp after it has moved to a background process?

8

2

I've just started using lftp for remote transferring files on my Raspberry Pi running Debian. I know how to transfer the files, and use queue and jobs to add and view transferring files.

However, I'm not actually sure on how to view these transfers once lftp moves to the background. The lftp man page mentions how lftp is moving to the background, but when I open a new instance of the program from shell and type jobs, the queue is empty. However, I can clearly see using my file manager that the transfers are still happening, as the files are there and growing in size.

I'm guessing that when I reopen lftp, it's just opening a new instance that isn't connected to the nohup mode lftp that has the active queue. I've tried searching various places, but no one else seems to have this particular issue.

So, I guess what I'm asking is twofold:

  1. Is there a way to easily attach to the background lftp process to view the current jobs list?

  2. If not, is there a way to view this at all?

drpfenderson

Posted 2012-09-15T01:24:39.647

Reputation: 183

Answers

12

You are correct that instances of lftp do not share the job queue, which is of course similar to how shell job queue works.

Still, lftp can indeed attach to an existing backgrounded session. According to lftp news version history, the feature was introduced in version 4.3.0 (2011-06-17). If your connection to lftp session disconnects or you exit with backgrounded transfers ongoing, with recent versions you can still resume the backgrounded lftp process and get access to its job queue.

From lftp man page:

attach [PID]

Attach the terminal to specified backgrounded lftp process.

To do this you need to know the process id, PID, of the backgrounded lftp process. A simple way to do this is the pgrep command, which lists matching process IDs.

For example, here I background a transfer in lftp:

lftp remote:/path> get oi-dev-151a-x86.iso 
[0] get oi-dev-151a-x86.iso &                                             
     `oi-dev-151a-x86.iso' at 655360 (0%) 296.1K/s eta:46m [Receiving data]
lftp remote:/path> exit
[82106] Moving to background to complete transfers...

This lists the pid needed to attach, but in case we did not have this noted down, we can find it again with pgrep:

$ pgrep lftp
82106

And here we resume the backgrounded lftp:

$ lftp
lftp :~> attach 82106
[82106] Attached to terminal.
lftp remote:/path> jobs
[0] get oi-dev-151a-x86.iso 
    `oi-dev-151a-x86.iso' at 42827776 (5%) 1.49M/s eta:10m [Receiving data]

The Debian stable version might not have the attach feature though, but you can still list the active lftp processes with pgrep.

joneskoo

Posted 2012-09-15T01:24:39.647

Reputation: 136

This is absolutely correct, though I'm very late commenting on that fact. Thank you very much. For those that come along later, pgrep actually did not work for me. I had to use "ps aux | grep lftp", as (for some reason) pgrep would sometimes not return a value when lftp was certainly running and found with ps aux. – drpfenderson – 2014-07-12T20:42:52.873

If parallel chunk downloads were initiated aka pget, then you can simply cat the file it generates (stored next to the actual file) to see the seek positions. Not very helpful, but gives you an indication. – Mohnish – 2018-11-10T23:49:37.367

1

From the lftp man page:

If  you exit lftp when some jobs are not finished yet, lftp will move itself to
nohup mode in background. The same happens when you have a real modem hangup or
when you close an xterm.

You cannot connect to background processes running with nohup if the parent process has terminated.

Yedric

Posted 2012-09-15T01:24:39.647

Reputation: 649

0

Collected from the lftp man page: Use ctrl-z to move the process in background and exit lftp, later start lftp again and type wait.

1398

Posted 2012-09-15T01:24:39.647

Reputation: 1