Jump to content

BASH: FTP Put Script

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I created this simple script to FTP data to another server:

#!/bin/sh -vx

# Script to FTP data to server
# Paramters:    host            FTP Server
#                     user            FTP Username
#                     passwd      FTP Password
#                     file             File to send/put
############################################################################

# Variables
HOST=$1
USER=$2
PASSWD=$3
FILE=$4
TONAME=$5

# Connect to FTP HOST and Send File
ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    dir
    ascii
    put $FILE $TONAME
   dir
   quit
END_SCRIPT
exit 0
Usage:
# ./ftpscript <host> <username> <passwd> <filename> <toname>
Example:
# ./ftpscript 127.0.0.1 jordan SomePass /var/log/messages /upload/messages.txt


#2
Hektor

Hektor

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Interesting. Is there no wput (opposite of wget) command?

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Yes, there is but it doesn't come "stock" on any Linux distro that I know of. Home of wput

#4
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
What do you mean with "stock", you mean out-of-the-box?

#5
Tor

Tor

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 486 posts
Yes I believe that is what he meant. "stock" is a term often used in English/America that means exactly like you stated: out-of-the-box with no enhancements.

#6
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
how a syntax to make password n username with list...like this

./ftpscript <host> <username.txt> <passwd.txt> <filename> <toname>

#7
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You'll need to change the script to read the files. You can use the 'cat' command for this.

#8
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
ohhh, use the cat for call a file text in to bash...
right or not...

#9
ikonia

ikonia

    Newbie

  • Members
  • PipPip
  • 24 posts
if you want to use sftp you can use ssh keys which removes the need for username / password.

#10
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You can use cat to read the contents of a file and add those contents to a variable.

#11
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
ok thanks master....

#12
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Interesting way of showing your gratitude.