LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Script to upload files to ftp directory (http://www.linuxquestions.org/questions/linux-software-2/script-to-upload-files-to-ftp-directory-776770/)

deibertine 12-18-2009 05:04 PM

Script to upload files to ftp directory
 
I want to implement a script for users to use when they need to upload a file into their ftp site.

The script that I'm hoping to do:
1. user runs script
2. script asks which directory to copy from
3. script asks which ftp directory
4. script initiates the move of files reading user's input from/to statement

Not so sure if this is possible in any way but would greatly appreciate if anyone has run into this before and could share ideas.

Cheers,
DB

EricTRA 12-18-2009 05:10 PM

Hi,

That's basic shell scripting, have a look at Bash beginners guide. Basically it's just what you would execute from a command line and put into a script with some interactions to get the user's input.

What have you tried so far and if tried, where is it failing?

If you have access to an ftp server, then open a console, try to put yourself in the user's place and execute the commands. Then substitute information that will be provided for a variable and fill that variable with the user's input; and so on.

Kind regards,

Eric

MBybee 12-18-2009 05:13 PM

Quote:

Originally Posted by EricTRA (Post 3797219)
Hi,

That's basic shell scripting, have a look at Bash beginners guide. Basically it's just what you would execute from a command line and put into a script with some interactions to get the user's input.

What have you tried so far and if tried, where is it failing?

If you have access to an ftp server, then open a console, try to put yourself in the user's place and execute the commands. Then substitute information that will be provided for a variable and fill that variable with the user's input; and so on.

Kind regards,

Eric

Agreed, and to build upon it, you may also want to look into Expect. There are sometimes some issues with handing off to FTP/SFTP that it can bridge.
http://www.tcl.tk/man/expect5.31/index.html

deibertine 12-18-2009 05:31 PM

Thanks for the immediate poste mates.
I'm a beginner so here's basically what I've done so far on my very basic bash script... :-)
Please note this is not done...

#!/bin/bash

# Ask user which directory to move from
echo "Please specify the directory path on where to move from:"

# Ask user which directory to move to
echo "Please specify the ftp directory path on where to move to:"

...hoping the next step to set variables to place user's input details.

Please advise if you can...

Cheers,
DB

EricTRA 12-18-2009 05:35 PM

Hi,

You're welcome and yes I agree, this is basic ;). Read the beginners guide for the part about variables and user input and like MBybee indicated look into Expect when it comes to the FTP communication. If you understand the part of how to get user input and the variables, then you'll have more than half the knowledge you need to finish your script.

Kind regards,

Eric

cpplinux 12-18-2009 05:43 PM

Try Perl with the FTP module.

MBybee 12-18-2009 05:45 PM

As a tip, this is what an Expect script tends to look like (though you'll be building yours on the fly, I imagine):

Code:

!/usr/local/bin/expect
spawn sftp hostname
expect "password:"
send "password\r"
send "ls /tmp\r"
expect "sftp> "
send "quit\r"

I build mine on the fly with Perl, but there are many ways to do it. As EricTRA pointed out, once you've mastered reading and writing data from a shell script, you're pretty much there.

<edit> Perl does have many tasty modules - but I'm not sure if you were looking into that as an alternative? It has the Net::SFTP/Net::FTP/Expect, etc. </edit>

deibertine 12-19-2009 12:36 PM

I'm sorry for not being clear on my first post...
I think I forgot to mention that users are expecting to upload their file in their ftp sites within the actual local ftp server.
For instance, my ftp server's hostname is ftpsrv1-dev.
User will login to ftpsrv1-dev and upload their file into their home folder.
Once uploaded, they will move this file from their home folder into the /var/www/html/ftpsite directory.
Now the issue im running on is permission:
$ ls -als
4 drwxrwxr-x 11 apache apache 4096 Dec 11 22:42 ftpsite

Should I just place all of my users to the "apache" group and that should take care of the problem?
I will try this today but hoping if you can give me other ideas as mentioned my above scenario.
So now I guess le "script" will just act as a "fronte" gui wizard for users so they would not have to do each commands manually themselves - rather just run le said script and follow wizard easily...

Cheers mates,
DB


All times are GMT -5. The time now is 03:17 AM.