LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-18-2009, 04:04 PM   #1
deibertine
Member
 
Registered: Mar 2009
Posts: 222

Rep: Reputation: 30
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
 
Old 12-18-2009, 04:10 PM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
1 members found this post helpful.
Old 12-18-2009, 04:13 PM   #3
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Quote:
Originally Posted by EricTRA View Post
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
 
Old 12-18-2009, 04:31 PM   #4
deibertine
Member
 
Registered: Mar 2009
Posts: 222

Original Poster
Rep: Reputation: 30
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
 
Old 12-18-2009, 04:35 PM   #5
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 12-18-2009, 04:43 PM   #6
cpplinux
Member
 
Registered: Dec 2009
Posts: 37

Rep: Reputation: 17
Try Perl with the FTP module.
 
Old 12-18-2009, 04:45 PM   #7
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
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>

Last edited by MBybee; 12-18-2009 at 04:47 PM. Reason: freaking typos
 
Old 12-19-2009, 11:36 AM   #8
deibertine
Member
 
Registered: Mar 2009
Posts: 222

Original Poster
Rep: Reputation: 30
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

Last edited by deibertine; 12-19-2009 at 11:39 AM. Reason: added script details...
 
  


Reply

Tags
bash, files, ftp, mv, script


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
[SOLVED] could not upload ftp files ah_gal06 Linux - Newbie 7 08-17-2009 09:44 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
upload files on ftp zafar466 Programming 2 12-14-2006 07:16 AM
Connection, login and upload files to ftp server via shell script Paulo Ges Linux - Networking 2 02-21-2004 01:01 PM


All times are GMT -5. The time now is 05:55 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration