Page 1 of 1
upload file to FTP server
Posted: Sat Apr 19, 2014 7:40 am
by benfany
hi everyone,
i am making project to read the temperature , pressure using AVR chip, and transferred to Raspberry pi,
i have already successfully generate txt File on my raspi folder, and next step this txt file will be uploaded into my ftp server in
different network on
ftp://xxx.yyy.zzz.nn (
need username and password to access this ftp server).
some tutorial give the idea to make PHP script which will be activated using cron daily,
i have no idea how to make this script and setting cron..
can someone let me know the php script and cron setting to make this automatically uploaded to my ftp server ?
file name : DSF-01.txt
thanks and regards,
benfany
Re: upload file to FTP server
Posted: Sat Apr 19, 2014 10:51 am
by DougieLawson
Don't use FTP, it's insecure.
Run sshd on the machine you're targeting and use scp on the RPi to send files over there. Or set-up a folder on the target that's shared with nfs or cifs and mount that on the RPi.
scp (using certificate authentication) doesn't need any special handling. It works just like a stock cp command (with a few syntactic anomalies).
scp /directory/subdirectory/filename_at_localhost user@remotehost:/remotedir/remotesubdir/filename_at_remote
Re: upload file to FTP server
Posted: Sun Apr 20, 2014 4:42 am
by benfany
Hi, thanks for suggestion
I would like to use about 10 raspberry and connected to my server. On my raspberry will be using GSM/3G internet connection, can we make it ssh with this situation? 10 raspi and 3G internet connection (dynamic IP)
Regards,
Benfany
Re: upload file to FTP server
Posted: Sun Apr 20, 2014 8:30 am
by DougieLawson
As long as your 3G service doesn't block port 22 then SSH is the best option.
Re: upload file to FTP server
Posted: Tue Dec 15, 2015 6:53 pm
by rjobaan
As I understand I need to use scp to transfer files from one pi to another but how can I do that
I am using this script
Code: Select all
#!/bin/bash
# LOCAL/FTP/SCP/MAIL PARAMETERS
SERVER="192.168.0.10" # IP of Network disk, used for ftp
USERNAME="root" # FTP username of Network disk used for ftp
PASSWORD="root" # FTP password of Network disk used for ftp
DESTDIR="/opt/backup" # used for temorarily storage
DOMO_IP="192.168.0.90" # Domoticz IP
DOMO_PORT="8080" # Domoticz port
### END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
BACKUPFILE="domoticz_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
BACKUPFILEGZ="$BACKUPFILE".gz
### Create backup and ZIP it
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /tmp/$BACKUPFILE
gzip -9 /tmp/$BACKUPFILE
### Send to Network disk through FTP
curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEGZ" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/media/hdd/Domoticz_backup/"
### Remove temp backup file
/bin/rm /tmp/$BACKUPFILEGZ
### Done!
But that is not working for me and as you say its not save.
So how can I change this script so its working and its secure. When script is done I want to schedule it with crontab so its backup daily
Re: upload file to FTP server
Posted: Wed Dec 16, 2015 9:00 am
by DougieLawson
Why not use scp? That's already there and will work.
Code: Select all
scp /tmp/$BACKUPFILE pi@192.168.0.90:/$SERVER/media/hdd/Domoticz_backup/$BACKFILE
The only pre-req for doing that is
sshkey-gen
ssh-copy-id pi@192.168.0.90
that generates /home/pi/.ssh/id_rsa and /home/pi/.ssh/id_rsa.pub then sends the public key from the source RPi to /home/pi/.ssh/authorized_keys on the target machine. That allows you to use scp without a password. You can do the same stuff for the root id (except you'll have to send the key by copying it a USB stick, or by using the pi userid to send it over the network).
Re: upload file to FTP server
Posted: Wed Dec 16, 2015 5:46 pm
by rjobaan
And when I use scp I still can schedule my *.sh to run daily?
Re: upload file to FTP server
Posted: Wed Dec 16, 2015 6:41 pm
by rjobaan
Question:when I use scp , can I still schedule my *.sh to run daily? in crontab?
When I use ssh pi@192.168.5.10 I can login into other pi without password but when I run below SH I need to logon
Code: Select all
#!/bin/bash
## LOCAL/FTP/SCP/MAIL PARAMETERS
SERVER="192.168.5.10" # IP of Network disk, used for: ftp mail scp
DOMO_IP="192.168.5.75" # Domoticz IP used for all
DOMO_PORT="8080" # Domoticz port used for all
## END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
## BACKUP DATABASE
BACKUPFILE="domoticz_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
BACKUPFILEGZ="$BACKUPFILE".gz
## BACKUP SCRIPTS
BACKUPFILEDIR="domoticz_all_$TIMESTAMP.tar.gz"
### Create backup and ZIP it
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /tmp/$BACKUPFILE
gzip -9 /tmp/$BACKUPFILE
##Back domoticz folder incl database
tar -zcvf /tmp/$BACKUPFILEDIR /home/pi/domoticz/
### Send to Network disk through SCP
scp /tmp/$BACKUPFILE pi@192.168.5.10:/$SERVER/media/WDBOOK/Domoticz_backup/$BACKFILE
scp /tmp/$BACKUPFILEDIR pi@192.168.5.10:/$SERVER/media/WDBOOK/Domoticz_backup/$BACKFILEDIR
### Remove temp backup files
/bin/rm /tmp/$BACKUPFILEGZ
/bin/rm /tmp/$BACKUPFILEDIR
### Done!
I run Sudo Backup.sh
after i will i see
pi@192.168.5.10's password:
/tmp/domoticz_20151216193620.db: No such file or directory
pi@192.168.5.10's password:
scp: /192.168.5.10/media/hdd/Domoticz_backup/domoticz_x_xxx_20151216193620.tar.gz: No such file or directory
What am I doing wrong
Re: upload file to FTP server
Posted: Wed Dec 16, 2015 7:01 pm
by DirkS
rjobaan wrote:What am I doing wrong
I think it's the use of 'sudo'.
scp / ssh will look for the key in the 'root' home dir instead of the one for 'pi' (that's the one you generated).
Looking at the commands you use, you don't need sudo at all, so just leave it out.
Re: upload file to FTP server
Posted: Thu Dec 17, 2015 8:39 am
by rjobaan
You are right now I don't have to fill in password
And I saw a mistake in script :
I changed script into
Code: Select all
### Send to Network disk through SCP
scp /tmp/$BACKUPFILEGZ pi@192.168.5.10:/$SERVER/media/hdd/Domoticz_backup/
scp /tmp/$BACKUPFILEDIR pi@192.168.5.10:/$SERVER/media/hdd/Domoticz_backup/
but still I am getting
scp: /192.168.5.10/media/hdd/Domoticz_backup/ No such file or directory
scp: /192.168.5.10/media/hdd/Domoticz_backup/ No such file or directory
when I run the scp code directly it is working
scp /tmp/domoticz_20151217095013.db.gz pi@192.168.5.10:/$SERVER/media/hdd/Domoticz_backup/
Re: upload file to FTP server
Posted: Thu Dec 17, 2015 9:08 am
by DirkS
rjobaan wrote:Code: Select all
### Send to Network disk through SCP
scp /tmp/$BACKUPFILEGZ pi@192.168.5.10:/$SERVER/media/WDBOOK/Domoticz_backup/
scp /tmp/$BACKUPFILEDIR pi@192.168.5.10:/$SERVER/media/WDBOOK/Domoticz_backup/
but still I am getting
scp: /192.168.5.10/media/hdd/Domoticz_backup/ No such file or directory
scp: /192.168.5.10/media/hdd/Domoticz_backup/ No such file or directory
Shouldn't the target of the operation just be the local path on the remote? In your command the remote IP address is added at the beginning of the target path
Code: Select all
scp /tmp/$BACKUPFILEGZ pi@192.168.5.10:/media/WDBOOK/Domoticz_backup/
or
Code: Select all
scp /tmp/$BACKUPFILEGZ pi@$SERVER:/media/WDBOOK/Domoticz_backup/
Re: upload file to FTP server
Posted: Thu Dec 17, 2015 9:22 am
by rjobaan
yes that was it. I removed $Server and it worked thanks!
I was wondering what is the difference between *.gz (this is used for backing up database) and *.tar.gz (this is used to backup the whole folder)
It seems I can not unzip *.gz files but I can *.tar.gz
So now next challenge
How can I combine those db files into one?
I have SQL Light running
Re: upload file to FTP server
Posted: Thu Dec 17, 2015 11:09 am
by DougieLawson
rjobaan wrote:
So now next challenge
How can I combine those db files into one?
I have SQL Light running
A new challenge == A NEW THREAD!
posting.php?mode=post&f=36
Re: upload file to FTP server
Posted: Thu Dec 17, 2015 12:03 pm
by rjobaan
DougieLawson wrote:rjobaan wrote:
So now next challenge
How can I combine those db files into one?
I have SQL Light running
A new challenge == A NEW THREAD!
posting.php?mode=post&f=36
Oh sorry ofcourse. Thank you very much for your help for far
How can I send file directly without zipping but adding timestamp to filename??
Code: Select all
scp /home/pi/domoticz/domoticz.db pi@/192.168.5.10:/media/hdd/Domoticz_backup/