LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-15-2015, 01:48 PM   #1
Gyrogypsy
LQ Newbie
 
Registered: Apr 2012
Location: Weybridge, Surrey
Distribution: Fedora 16
Posts: 13

Rep: Reputation: Disabled
FTP Upload Script


Good Evening,

I am struggling with an automated script to upload a file to an FTP server.
Code:
#!/bin/sh
HOST="webcam.wunderground.com"
USER="XXXXXCAM2"
PASSWD="XXXXXXX"
FILE="/mnt/DoomNet/WeatherCAM1.jpg"
if [ -r $FILE ] && echo "File Exists" || echo "File does not exist"
then
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
fi
exit 0
Right now, I get the "File Exists" response, but immediately following this I get
"Can't open that file: No such file or directory". Can anybody help me here as I am banging my head against a wall. I am quite new to Linux so I am hoping this is something fundamental I am missing.

Thanks everybody
Gyro
 
Old 06-15-2015, 01:51 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,309

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Gyrogypsy View Post
Good Evening,

I am struggling with an automated script to upload a file to an FTP server.
Code:
#!/bin/sh
HOST="webcam.wunderground.com"
USER="XXXXXCAM2"
PASSWD="XXXXXXX"
FILE="/mnt/DoomNet/WeatherCAM1.jpg"
if [ -r $FILE ] && echo "File Exists" || echo "File does not exist"
then
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
fi
exit 0
Right now, I get the "File Exists" response, but immediately following this I get
"Can't open that file: No such file or directory". Can anybody help me here as I am banging my head against a wall. I am quite new to Linux so I am hoping this is something fundamental I am missing.

Thanks everybody
Gyro
i sound like a broken record but why are folks adverse to scp/sftp ?
the part in purple seems weird to me ?

Last edited by schneidz; 06-15-2015 at 01:54 PM.
 
Old 06-15-2015, 03:26 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,745

Rep: Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599
I agree but not in this case. The OP is uploading pictures to the Weather Underground web site.

http://wiki.wunderground.com/index.php/WunderCams_FTP

As far as I know ftp does not understand absolute file paths. You need to change the directory using cd before executing the ftp command or lcd in your here doc. Make sure you are in binary mode too.

Have you manually transfered files yet?
 
1 members found this post helpful.
Old 06-15-2015, 04:03 PM   #4
Gyrogypsy
LQ Newbie
 
Registered: Apr 2012
Location: Weybridge, Surrey
Distribution: Fedora 16
Posts: 13

Original Poster
Rep: Reputation: Disabled
Hi,

You are correct, Wunderground does not support SFTP.

Yes, I have manually transferred the files and it is updating perfectly. I will try the absolute path route like you suggest.

Many thanks for your help!!
Gyro
 
Old 06-15-2015, 04:07 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,745

Rep: Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599
Make sure you remove the absolute path in your script i.e. file=image.jpg.
 
Old 06-16-2015, 02:01 AM   #6
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Scripting like this is error prone. What if there is time async for commands.

Best would be to use a ftp client to upload/download. E.g. 'ncftp' or 'lftp' or others.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script to automate ftp upload mabin Linux - General 4 12-19-2018 06:48 AM
Script to upload files to ftp directory deibertine Linux - Software 7 12-19-2009 11:36 AM
Expect script to automate ftp upload mabin Linux - Newbie 1 10-18-2008 11:36 AM
ftp upload script problem. please help pinkygoyal Programming 8 02-15-2008 03:20 PM
buggy ftp upload script rblampain Programming 5 05-20-2007 12:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration