FTP sript help - Suse

This is a discussion on FTP sript help - Suse ; Hi all Looking for some FTP script help. I am trying to automate getting files from my web site and send them directly to a printer. Here is what I have: ftp open ftp.mydomain.com user ftpuser ftp pwd cd /home/myusername/public_html/uploads/files ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: FTP sript help

  1. FTP sript help

    Hi all

    Looking for some FTP script help.
    I am trying to automate getting files from my web site and send them
    directly to a printer.
    Here is what I have:
    ftp
    open ftp.mydomain.com
    user ftpuser
    ftp pwd
    cd /home/myusername/public_html/uploads/files
    lcd /home/me/test
    binary
    mget /files
    # I am failing here..
    # I want to delete all present files.
    disconnect
    bye

    How and where would I stick the printing line, if possible at all?



    --
    Jerry Maguire: Help me... help you. Help me, help you. ;-)

  2. Re: FTP sript help

    Holz wrote:
    > Hi all
    >
    > Looking for some FTP script help.
    > I am trying to automate getting files from my web site and send them
    > directly to a printer.


    The first I can help. The second is another issue. best treat it
    seperately. Once you have the two solutions, you can easily put them
    together

    > Here is what I have:
    > ftp
    > open ftp.mydomain.com


    Please use example.com as domain, so here ftp.example.com. That way we
    are sure it is an example and will not try to solve problems

    > user ftpuser
    > ftp pwd
    > cd /home/myusername/public_html/uploads/files
    > lcd /home/me/test
    > binary
    > mget /files
    > # I am failing here..
    > # I want to delete all present files.
    > disconnect
    > bye


    I would use ncftp. Much easier. Also what I do is have a file
    ~/.passwords that I have given the rights to read only to me. (chmod
    400)
    ~/.passwords woul look like this:
    #Passwords. Chmod to 400
    #Logins for ftp.example.com
    ftplogin=ftpuser
    ftppass=pa55word
    #logins for www.example.org
    wwwlogin=otheruser
    wwwpass=PaSwOrD
    ....

    If you have logins and/or passwords that are the same, you do not need
    to add thm several times, but it might be handy

    Here an untested script:

    #!/bin/bash
    set -x
    LOCALDIR=/home/myusername/public_html/uploads/files
    REMOTE=/home/me/test
    .. ~/.passwords
    ncftpput -u $ftplogin -p $ftppass ftp.example.com $REMOTE $LOCALDIR/* && rm $LOCALDIR/*
    # your print command here

    So what does this little thing do?
    First it shows you everything it does. Once everything works, you can
    remove the `set -x` or just put a # in front of it to comment it out.
    Next it gives two parameters, so if you later need to change it, you do
    not need to change everything, which might be a problem when you start
    adding things.
    It the reads (sources) the file ~/.passwords. Do not forget the '.'
    (dot) on the beginning of the line.
    The advantage of this is that you can share your script without the need
    of being afraid you might copy and paste your password by accident.
    Next it runs ncftpput (install ncftp and read man ncftp and man ncftpput
    on more) It basicaly will upload all files.

    The neat part is the '&&'. That thing will do whatever is behind it if
    things work out OK. This means if your ncftp did NOT work, files WON'T
    be deleted.
    That can be handy if you have a network issue you did not know about.
    It could be frustrating that files are deleted if you did not yet want
    that happening.

    Understand that this is extremely basic testing. If you want more
    testing before deleting, you need to use if, then, else.

    > How and where would I stick the printing line, if possible at all?


    It is not clear to me what you want to print.
    Also this will print after the removal and even if there was no removal.
    Instead of printing, you could also email or even sms if that is what
    you want. ;-)

    houghi
    --
    This was written under the influence of the following:
    | Artist : Emerson, Lake and Palmer
    | Song : Piano improvisation
    | Album : Welcome back my friends ...

  3. Re: FTP sript help

    On Sat, 03 May 2008 01:38:37 +0200, houghi wrote:


    > It is not clear to me what you want to print. Also this will print after
    > the removal and even if there was no removal. Instead of printing, you
    > could also email or even sms if that is what you want. ;-)
    >
    > houghi


    Thanks for the detailed answer.
    I am trying to to print the pdf files I download. I need to print rather
    then e-mail.

    --
    Jerry Maguire: Help me... help you. Help me, help you. ;-)

  4. Re: FTP sript help

    Holz wrote:
    > On Sat, 03 May 2008 01:38:37 +0200, houghi wrote:
    >
    >
    >> It is not clear to me what you want to print. Also this will print after
    >> the removal and even if there was no removal. Instead of printing, you
    >> could also email or even sms if that is what you want. ;-)
    >>
    >> houghi

    >
    > Thanks for the detailed answer.
    > I am trying to to print the pdf files I download. I need to print rather
    > then e-mail.


    OK, Now I am embaressed. I was thinking of uploading things.

    So please start over again. You have things on your ftp site that you
    want to download and then print and the delete the downloaded stuff?

    Why not just use something like ftp://userassword@ftp.example.com and
    go from there? Probably you can even print it directly.

    houghi
    --
    This was written under the influence of the following:
    | Artist : Within Temptation
    | Song : Restless
    | Album : Enter

  5. Re: FTP sript help

    On 2008-05-02 23:56, Holz wrote:
    > Hi all
    >
    > Looking for some FTP script help.
    > I am trying to automate getting files from my web site and send them
    > directly to a printer.
    > Here is what I have:
    > ftp
    > open ftp.mydomain.com
    > user ftpuser
    > ftp pwd
    > cd /home/myusername/public_html/uploads/files
    > lcd /home/me/test
    > binary
    > mget /files
    > # I am failing here..
    > # I want to delete all present files.
    > disconnect
    > bye
    >
    > How and where would I stick the printing line, if possible at all?
    >
    >
    >


    Instead of making ftp scripts you can use .netrc and make a macro
    named print for example.

    A macro named init will be run every time you call ftp.

    The file .netrc must be protected from other users, or it refuse to work,
    chmod 600

    Example of ~/.netrc

    machine ftp.mydomain.com login ftpuser password the_password
    macdef print
    prompt off
    binary
    cd /home/myusername/public_html/uploads/files
    lcd /home/me/test
    mput * (I guess it was put and not get)
    ! mv * ../uploaded (rm is maybe a bit unsafe)
    bye


    Then call the macro with:
    echo \$print | ftp ftp.mydomain.com

    and it do what you told it.

    /bb

+ Reply to Thread