Find the answer to your Linux question:
Page 1 of 5 1 2 3 4 5 LastLast
Results 1 to 10 of 42
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Shell Scripting: How to put an ftp session in the background from ftp prompt

    I am looking for a way, in a bash script to put ftp in the background from an "ftp>" prompt. Normally I could hit <cntrl><alt><Fx> where "x" is some number, however you can't really press physical keys in a shell script.

    Any ideas?


  2. #2
    Apparently issuing a "!" when in the ftp> prompt suspends the ftp client and gives a shell prompt then issuing "exit" in the shell allows one to get back into the ftp client. This works fine manually, however my shell script seems to igore the "!". When I debug my shell script, it reveals that "!" is not being sent to the ftp prompt at all, I think "!" must unfortunately be a reserved character for bash shell scripts. Any ideas how to get around this (ie. perhaps something I can put in front of the "!" to ensure the bash script sends it to the prompt like other commands?"


  3. #3
    Have you tried putting backslash in front of the ! ie the character \ ?

  4. $spacer_open
  5. #4
    I'll give it a shot, I just tried putting single quotes around the ! to make it '!' but that didn't work.

  6. #5
    Ok, I just tried /! (command was ignored alltogether) with no luck as well as /'!' with no luck (got an ?Invalid command error message). Hmmm... Any other suggestions?

  7. #6
    Show us how you're passing the string containing the '!' to ftp and we might be able to help.

  8. #7
    For instance if I write a script like this:
    ftp -vn <<SCRIPT
    user myusername mypassword
    exit 0
    Then the following will occur line by line as follows:

    !   # this will be ignored as seen by the outcome of "ls"
    ls # this should list the contents of the local directory not that of
       # the ftp, but in practice it lists the contents of the ftp, because 
       # "!" never susspended ftp to bring back the shell
    SCRIPT # this logs out of and quits the ftp client applicaton entirely
    Thus it appears the ! character is reserved for something special in
    shell scripts and thus presents a problem for what I am attempting to
    do. The ! character appears to pose an even greater issue when
    including it in a shell while loop.

    I've attempted replacing ! with '!', `!`, /! and /'!' none of which brought about any success.

  9. #8
    I suggested using backslash which is \
    Instead you used forward slash ie /

  10. #9
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Lat: 39:03:51N Lon: 77:14:37W
    I'm assuming you are downloading something from a ftp server and are attempting to run other commands while that happens in the background. Check out wget and curl, interactive programs like the default ftp client are not scribtable, as they grab the keyboard input and suspend the background shell, enter ! opens a NEW shell.

    On a similar note, assuming you are grabbing a file from

    wget & //<-- the ampersand backgrounds this process and contiunes to execute the script
    cat /var/log/vsftpd | grep ERROR > errorlog
    Avoid the Gates of Hell. Use Linux
    A Penny for your Thoughts

    Formerly Known as qub333

  11. #10
    I should have mentioned this is an embedded system with a bug that makes installing additional apps like wget and curl extremely difficult. I've had no problems scripting the default ftp client in the past, the issue only comes up when I need to performs tasks without closing my ftp connection. Let me check on that / vs. \ issue. I may have just entered the wrong slash on the forum or perhaps I tried the wrong slash in my code. I'll go ahead and verify that...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts