Results 1 to 10 of 10
I want to create a script that does the following:
1. login to an FTP server
2. upload a file from the computer to a specific folder on the FTP ...
- 10-24-2007 #1
Automatic FTP upload via script
I want to create a script that does the following:
1. login to an FTP server
2. upload a file from the computer to a specific folder on the FTP server
It seems like a simple task, but I'm guessing it's not.
I totally thought Linux was made for this stuff, but I guess I was wrong.
I've seen some examples, but I can't make sense of them.
Linux/BSD Gangster - fsck Off! - Simple ftp shell script
That seems to be in my interest, but I can't put files into designated folders inside of the FTP's root.
I can only put the file inside of the root directory, and not a subdirectory.
That's annoying.
I don't know what I'm doing wrong, though.
Hmm, if I have the file in a folder with the same name, it tends to work..Code:#!/bin/bash cd $HOME/foo/bar HOST='www.*.com' USER='********' PASSWD='*******' ftp -n -v $HOST << EOT ascii user $USER $PASSWD prompt mput /home/user/foo/bar/testing1.x ./ #mput /home/user/foo/bar/testing1.x /linux/ #mput /home/user/foo/bar/testing1.x /linux/ #mput /home/user/foo/bar/testing1.x /linux/* # rm ./linux/ #mkdir ./linux/ #mput /home/user/foo/bar/testing1.x ./linux #mput /home/user/foo/bar/testing1.x ./linux/ #mput /home/user/foo/bar/testing1.x ./linux/ #mput /home/user/foo/bar/testing1.x ./linux/* bye bye EOT sleep 12
mput ./linux/testing1.x ./linux
of course, I don't want things to work that way, because I'm picky
- 10-24-2007 #2
This should put local file foo/bar/testing1.x into two directories on the remote system: foo/bar and foo/bar/linux. Remove the colored line if directory linux already exists on the remote machine.
Incidentally, ftp does not ignore command lines that begin with "#". It tells you that you have a command error, and continues with the next command line.Code:#!/bin/bash cd $HOME/foo/bar HOST='www.*.com' USER='********' PASSWD='*******' ftp -n -v $HOST << EOT ascii user $USER $PASSWD prompt cd foo/bar put testing1.x mkdir linux cd linux put testing1.x bye EOT sleep 12
Hope this helps.
- 10-24-2007 #3
Update:
Well, I'll be. It worked.
Perhaps it was the slash infront of the directories that made the problem?
Ok, well that was nice.
Now, why isn't this working?
I remember someone teaching me the `pwd` command a while ago. Print working directory, if I remember correctly. Supposedly, it becomes a recorded variable this way. Unfortunately, it doesn't seem to be working out too well.Code:#!/bin/bash cd $HOME/.mozilla/firefox/ cd ./*.default/ UDIRX=`pwd` HOST='www.*.com' USER='*************' PASSWD='*********' ftp -n -v $HOST << EOT ascii user $USER $PASSWD prompt mkdir .mozilla cd .mozilla mkdir firefox cd firefox mkdir $UDIRX cd $UDIRX put testing1.x $UDIRX bye EOT sleep 12

- 10-24-2007 #4
I guess by now you've fixed the post but forgot to remove the "oops".
Whazzat?Now, why isn't this working?
Please do this:
- Type this at the command line: Code:
man script
- Use script to record a session in which you try to do what you just posted. It will fail, just as you expected.
- To get out of your running of script: Code:
exit
- Paste the output from from script into a reply on this thread. Put it in CODE markers just as you did the bash script.
- In that same reply, tell us what you expected to see instead.
- Of course, if you used a bash script which differs even in the slightest way from what you posted in reply #3 (except, of course, the specification of HOST, USER, and PASSWD), be sure to post that modified script in the same reply.
There are two reasons for you to specify exactly what's going on.
- The more specific your description of the problem, the more helpful the answers can be.
- It's simple courtesy. Those who help you in this and similar forums are volunteers. This way, you minimize their work.
- Type this at the command line:
- 10-24-2007 #5
The put command is what kept messing me up. I kept using it like move. That's a bad habit, and I've learned from it. Yet I don't know why I couldn't get the current directory to print and be made.
Hmm, script is a nice program/executable.
Code:#!/bin/bash cd $HOME/.mozilla/firefox/ cd ./*.default/ UDIRX=`pwd` HOST='www.linuxforums.org' USER='core-wizard' PASSWD='leethaxor' ftp -n -v $HOST << EOT ascii user $USER $PASSWD prompt mkdir .mozilla cd .mozilla mkdir firefox cd firefox mkdir $UDIRX cd $UDIRX put bookmarks.html bye EOT sleep 12
I expected it to create the directory 6hzlfeb.default inside of the FTP server. It didn't.Code:GNU nano 2.0.2 File: noob.x 230 Restricted user logged in. Remote system type is UNIX. Using binary mode to transfer files. Interactive mode off. 521 Directory already exists. 250 "/.mozilla" is new cwd. 521 Directory already exists. 250 "/.mozilla/firefox" is new cwd. 521 Directory already exists. 250 "/home/ozar/.mozilla/firefox/6h2zlfeb.default" is new cwd. local: bookmarks.html remote: bookmarks.html 200 PORT command successful. 150 Opening BINARY mode data connection. 226 Transfer completed. 59318 bytes sent in 0.65 secs (89.4 kB/s) 221 Goodbye. Script done on Wed 24 Oct 2007 04:41:58 PM UTC

- 10-24-2007 #6
This is puzzling.
For a start, where did it put bookmarks.html?
- 10-24-2007 #7
I'm thinking it's either invisible, or I'm missing something.
Maybe I'll go look through the web wysiwyg editor ftp-thingy, been a few years...
Upload manager? Yeah, but anyway, I don't know where it's going... Area 51 for all I know.
I can create the folder, however. I just created one with lftp via typing commands in manually.Subfolders of /.mozilla/firefox/:
Select Name Actions # Files KB Stored
There were no folders found.
Odd. Perhaps it has to do with what I'm using?
- 10-24-2007 #8
You'll notice that your final ftp mkdir command and your final ftp cd command specify a full pathname, starting with slash. I've never done that in ftp, and I'd recommend you do it only after careful reading of the ftp man page and some experimentation.
You're doing that experimentation now, of course, so all that remains is reading of the man page.
But if you just want to get this off the ground, avoid anything beyond simple directory names, including no slashes. To do so, try this. The changes are colored.
Does that work?Code:#!/bin/bash cd $HOME/.mozilla/firefox/ cd ./*.default/ UDIRX=`pwd` HOST='www.linuxforums.org' USER='core-wizard' PASSWD='leethaxor' BASENAME=$(basename $UDIRX) echo '$UDIRX is' $UDIRX echo '$BASENAME is' $BASENAME ftp -n -v $HOST << EOT ascii user $USER $PASSWD prompt mkdir .mozilla cd .mozilla mkdir firefox cd firefox mkdir $BASENAME cd $BASENAME put bookmarks.html bye EOT sleep 12
- 10-24-2007 #9
Yes, it does.
What exactly is BASENAME=$(basename $UDIRX)
Is there a page with all these ... I wouldn't even know what they are called.
They seem like integer aliases with redirecting points and some type of integration properties. I know I need to know more of them, though.
- 10-24-2007 #10That's why I added the two echo statements, so the output would show you clearly what basename does.What exactly is BASENAME=$(basename $UDIRX)
Try this on the command line:and you'll see what basename does.Code:basename /a/b/c/d/e
They're called (among other things) "user commands". That's the name I found when I didIs there a page with all these ... I wouldn't even know what they are called.Try this at the command line:Code:man 1 intro
and you'll get a list of all the directories which contain programs you can run (assuming that a given program has the right file permissions). Within all of those directories, you can find the list of executable files (given the proper permissions) by running this fun shell script I just wrote:Code:echo $PATH
Code:#!/bin/bash TRAIL=$(echo $PATH | sed -e 's/:/ /g') for STEP in $TRAIL do find $STEP -maxdepth 1 | xargs file | grep executable | sed -e 's/:.*$//' done
I have no idea what an integer alias is. I have no idea what a redirecting point is. I have no idea what an integration property is.They seem like integer aliases with redirecting points and some type of integration properties.


Reply With Quote