LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-29-2004, 10:04 PM   #1
UmneyDurak
Member
 
Registered: Jun 2004
Posts: 178

Rep: Reputation: 30
Upload script


Hi.
I'm uploading certain files using sftp to the server. Is it possible to create a bash script that would do it automatically?
Thx.
 
Old 07-29-2004, 10:29 PM   #2
Ankheg
Member
 
Registered: Jul 2004
Location: Woodland Hills, CA
Distribution: Debian/Mandrake
Posts: 37

Rep: Reputation: 15
Looking at sftp (with Cygwin at the moment, but it should be extremely similar if not the same).

Just from typing "sftp -help" I see a few things that make me think it's definitely possible. Most notable being the line "sftp [[user@]host[:file [file]]]", and maybe even better, the option above "[-b batchfile]".

Knowing nothing about the batchfile option, and little about the file specifications in the other, I take myself over to the man page for it (man sftp).

The batchfile option looks like it will probably be exactly what you are looking for...

Code:
-b batchfile
        Batch mode reads a series of commands from an input batchfile
        instead of stdin.  Since it lacks user interaction it should be
        used in conjunction with non-interactive authentication.  A
        batchfile of `-' may be used to indicate standard input.  sftp
        will abort if any of the following commands fail: get, put,
        rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp,
        lpwd and lmkdir.  Termination on error can be suppressed on a
        command by command basis by prefixing the command with a `-'
        character (for example, -rm /tmp/blah*).
So, looking at this, it looks as if you could simply make a file (we'll call it batch.ftp), and put a series of commands in it, each on their own line. For example (note: this assumes you are achieving access without a password prompt thanks to ssh keys in place...if that's not the case, let me know and we can either help set that up for you, or get around it another way):

Code:
put myfile1.txt
cd myfiles
put myfile2.txt
My understanding is that this file, run at the command line with sftp like this: sftp -b batch.ftp user@host
Will result in you connecting, putting myfile1.txt in your login directory, changing to the myfiles directory, and putting myfile2.txt into the myfiles directory.

All in all, I think this will get the result you're looking for...I hope...

I have to apologize too, I get to wordy at times and tend to have scatterbrained thoughts, so please forgive me if that's the case, and just tell me to clarify.
 
Old 07-30-2004, 02:52 PM   #3
UmneyDurak
Member
 
Registered: Jun 2004
Posts: 178

Original Poster
Rep: Reputation: 30
Thanks. I was gunho to do it through bash scriptting, didn't even think of seeing if sftp already has something that can do it.
sftp -b batchfile login@host does the trick.
After connection it asks for password, and once connected it executes all the commands and exits.
 
  


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
Recursive Upload Script Kenji Miyamoto Linux - General 1 09-01-2005 11:18 PM
Upload Script....but not php vous Programming 1 02-04-2004 02:13 PM
What's a good php upload script for this? kleptophobiac Programming 2 01-31-2004 07:06 AM
photo upload script mohapi Linux - Software 0 07-15-2003 10:21 AM
Shell File Upload Monitor Script noodle123 Programming 0 04-22-2002 11:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:42 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