[Solved] Simple Shellscript for uploading files to a specific folder on a ftp-server?

hi!
Iam using my D-link DNS-320 (NAS) with fun_plug installed (a unix client)

I am currently using cron to run a shellscript running a java-application that creates a couple of txt files.

These files needs to be uploaded to a specific folder on my webhosts ftp server-account.

I need a simple shellscript that does this, (to be scheduled as a cron-job)

Iam some what of a novice regarding this so simple answers and examples is greatly appreciated :slight_smile:

Have you searched the forums?

Yes I have tried a bunch of these scripts, but I havent got anyone working, thats why I started a new thread =)

The point isthe tasks are not all that simple, and cannot help if you dont give more information so the best would be to find a simple ftp script, adapt it, THEN come here and submit the issue with all needed information like logs error messages etc... Then we can methodically try to help you solve...
Q1 : Are you trying to use the true FTP ?
Q2 : Is you NAS on the same network
Q3 : Has your NAS some firewall activated?
Q4: etc....

Q4: What have you achieved so far?
Q5: ...

Either way, i'd assume that the generation of those text files from the java-app should be the 'very same' script that parses them after...

Ok thanks for your help:) Im sorry if there was a lot of information missing, we live and we learn;-)

Ok...
The script that seems to match my needs is:

#!/bin/bash

HOST=ftp.server.com  #This is the FTP servers host or IP address.
USER=(myftpusername)             #This is the FTP user that has access to the server.
PASS=mypassword          #This is the password for the FTP user.

# Call 1. Uses the ftp command with the -inv switches.  -i turns off interactiv$

ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.

user $USER $PASS

# Call 3. Here you will change to the directory where you want to put or get
cd /public_html/fotosupport.se/Nigge

# Call4.  Here you will tell FTP to put or get the file.
put test.txt

bye
EOF

When I run it I get the following:

And once again, thanks a lot for your help:-)

Look at line 2 of your log. Seems like you are using an incompatible ftp- version.

What surprises me is that the log is not clear : Looks more like a ftpd log to me aka ftpserver and not the ftp client...
more Q: what OS and version are you using? and what shell... ( I suppose a minimalist linux version since you mentinned D-link...)
If we are talking of files generated on the D-link to be uploaded elsewhere on the same device then simple copy cp or mv could do the job no?

Ok, I tried another script using curl instead.
this script is even simplier...

curl -u "username:password" --upload-file test.txt ftp.b10.levonline.com/public_html/fotosupport.se/Nigge --no-epsv

This time all I get is the following:

Any tips?:slight_smile:

---------- Post updated at 12:57 PM ---------- Previous update was at 12:47 PM ----------

Yes, that was my guess as welll, I dont know what ftp-client to use and how to make the scripts for that one, I installed curl but I got another error message on that one:)

The OS-version is Linux dlink-469621 2.6.22.18 #23 Wed May 25 15:48:30 CST 2011 armv5tejl GNU/Linux"
I guess its a minimalistic version yes,

Its not files generated by the D-link but generated by a java application, but they are just two txt-files, however I want to access them via the internet so I want them on my the webserver where I have my webpage (levonline)

So thats why I need a FTP-upload

---------- Post updated at 01:00 PM ---------- Previous update was at 12:57 PM ----------

When I try to upload it onto the root of the ftp-server it works
So I guess its the upload to a specific part on the ftp server that doesnt work...
So...
curl -u username:password --upload-file test.txt ftp.bxx.levonline.com works

but

curl -u username:password --upload-file test.txt ftp.bxx.levonline.com/fotosupport.se/Nigge
doesnt work at all

@vbe: correct - but then his ftp command (used in the script) might be a link? an alias? a renamed server entry?

curl -u username:password --upload-file /ffp/home/root/1282123.txt ftp.b10.levonline.com/public_html/fotosupport.se/Nigge/

this made it work! when i ran the shellscript
but when I schedule it to cron, it does not work anymore...

what might be wrong?

This question is so common its in our FAQ.

cron does not have the same PATH settings you have. Try /absolute/path/to/curl, which you can get with 'which curl' or 'whereis curl'.

I am using the complete path to curl...?

#! /bin/sh
/ffp/bin/curl -u user_password --upload-file /ffp/home/root/1282123.txt ftp.b10.levonline.com/public_html/fotosupport.se/Nigge/

OK, so what did you put in your crontab then?

*/10 * * * * /mnt/HD/HD_a2/Nigge/SensorReader/ftp.sh

Are you sure you device supports */10 syntax ?

Yes I am,

Ok the problem is now solved. there was a problem with the crontab...I moved the rows around and then it worked...

Thanks everybody for your help!