FTP script
Started by: CreakyCreaky
On: 1245436841|%e %b %Y, %H:%M %Z|agohover
Number of posts: 8
rss icon RSS: New posts
FTP script
CreakyCreaky 1245436841|%e %b %Y, %H:%M %Z|agohover

I have the following script that I am trying to get to work, if its possible of course. When I run the script I get an error message which is

ftp: line 8: ftp: command not found

Will this sort of thing actually work, and if so what else do I need to install. I have vsftpd installed and running and thought that would do the trick.

HOST="ftp.com"
USER="backups"
PASSWD="pass"

DATE=$(date +"%Y-%m-%d")
FILE="dbbackup_$DATE.sql.gz"

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD

binary
get $FILE
quit
unfold FTP script by CreakyCreaky, 1245436841|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
fraterfrater 1245437967|%e %b %Y, %H:%M %Z|agohover

vsftp is an FTP-server.
You need an ftp-client…

ipkg install inetutils

Yes, I think that code will work (although I didn't look at it in detail)
If it doesn't you can try something like this:
(I wrote this a long time ago and would do it more elegant now…)

FILE="4MB.zip"
FTPU="user"
FTPP="pass"
FTPS="ftp.mirmana.com 31"

ftp -v -n ${FTPS} <<EOF >>${TMPLOG}
user ${FTPU} ${FTPP}
binary
get ${FILE} ${FILE}.bak
put ${FILE}
quit
EOF

It can even be done in windows…..

@ECHO OFF
SET FTPS=89.250.176.48
SET USER=login
SET PASSWORD=pass
SET FTPDIR=.
SET FILE=4MB.zip

ECHO open %FTPS%>%FTPS%.ftp
ECHO %USER%>>%FTPS%.ftp
ECHO %PASSWORD%>>%FTPS%.ftp
ECHO BIN>>%FTPS%.ftp
ECHO cd %FTPDIR%>>%FTPS%.ftp
ECHO get %FILE%>>%FTPS%.ftp
ECHO put %FILE% %FILE%.bk>>%FTPS%.ftp
ECHO bye>>%FTPS%.ftp

ftp -i -s:%FTPS%.ftp
del /q %FILE%
del /q %FTPS%.ftp
pause
last edited on 1245438026|%e %b %Y, %H:%M %Z|agohover by frater + show more
unfold Re: FTP script by fraterfrater, 1245437967|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
tomas123tomas123 1245439629|%e %b %Y, %H:%M %Z|agohover

on the white book are two ftp clients on board:

~ # /usr/bin/ftpget
BusyBox v1.1.1 (2008.11.20-08:20+0000) multi-call binary
Retrieve a remote file via FTP
Usage: ftpget [options] remote-host local-file remote-file
Options:
            -c,--continue   Continue previous transfer
            -v,--verbose    Verbose
            -u,--username   Username
            -p,--password   Password
            -P,--port       Port number

and for secure ftp (Port 22)

~ # /usr/bin/sftp
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
            [-o ssh_option] [-P sftp_server_path] [-R num_requests]
            [-S program] [-s subsystem | sftp_server] host
       sftp [[user@]host[:file [file]]]
       sftp [[user@]host[:dir[/]]]
       sftp -b batchfile [user@]host
unfold Re: FTP script by tomas123tomas123, 1245439629|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
CreakyCreaky 1245441580|%e %b %Y, %H:%M %Z|agohover

Thanks a lot guys, been a great help.

Can now log in but I'm getting an error message around line 6. Any suggestions?

line 6: unexpected EOF while looking for matching `"'

This is line 6

FILE="dbbackup_$DATE.sql.gz"
last edited on 1245444476|%e %b %Y, %H:%M %Z|agohover by Creaky + show more
unfold Re: FTP script by CreakyCreaky, 1245441580|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
CreakyCreaky 1245508203|%e %b %Y, %H:%M %Z|agohover

Think I've sorted out the above but now getting a Connection timed out error message. I can connect to the ftp server using the same user & pass using filezilla but not from the mybook. I'm logging in to the mybook using putty on a Vista machine if that makes any difference.

unfold Re: FTP script by CreakyCreaky, 1245508203|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
CreakyCreaky 1245691591|%e %b %Y, %H:%M %Z|agohover

I now have the script running perfectly when I call it manually but can't get it to work from a cron job. I know cron is installed as I have used a script from frater to install it, I have place my script in the cron.daily directory.

How do I get the script to run using cron?

unfold Re: FTP script by CreakyCreaky, 1245691591|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
fraterfrater 1245696432|%e %b %Y, %H:%M %Z|agohover

Did you start your script with…?

#!/bin/sh

I think not
If you forget this, the command will run from the prompt and run bash (because it's invoked from bash)
If you invoke it from cron, it doesn't know what to do with it….

remember….

In Linux you always have to tell exactly what you want. In windows it will try and correct "false" parameters and then execute the job without giving you any message. This will also mean it can do other things than you really wanted.

unfold Re: FTP script by fraterfrater, 1245696432|%e %b %Y, %H:%M %Z|agohover
Re: FTP script
CreakyCreaky 1245704853|%e %b %Y, %H:%M %Z|agohover

No I didn't, still trying to learn all this.

unfold Re: FTP script by CreakyCreaky, 1245704853|%e %b %Y, %H:%M %Z|agohover
New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License