LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   ftp script (https://www.linuxquestions.org/questions/linux-networking-3/ftp-script-144516/)

dlm4444 02-10-2004 01:48 PM

ftp script
 
I trying to automate an ftp script. it doesnot seem to be working. I can ftp manually with out problem. when done manually I can input username and password.
how do I input username and password in the script so the script will work?
both machines have the same username and password
I trying to ftp a file from redhat 9.0 to redhat 9.0


#bin/bash

cd /home/david

ftp 2.3.2.3 <<EOF
put stuff.tar.gz

bye
EOF

homey 02-10-2004 02:39 PM

In this example, I'm using *.txt which you aught to be able to change for your needs.

Code:

#!/bin/bash
ftp -i ftp.server.com <<EOF
for n in *.txt
do
mput $n
done
bye \n
EOF


dlm4444 02-10-2004 03:03 PM

thanks, but the script didn't help much.

Is there a way for autologin through ftp?

Linux_in_NH 02-10-2004 03:09 PM

Take a look at wget (http://www.gnu.org/software/wget/wget.html)
or rsync (http://rsync.samba.org/) or scp (part of SSH http://openssh.org/)

Much simplier.

jazernorth 02-10-2004 03:11 PM

Try Python (www.python.org) instead of sh/bash.

It would be something like:
Code:

#!/sbin/python # location of python binary

# user name and password

user_id = 'myusername'
passwd = 'mypassword'

#file to transfer
pc_file_name = 'stuff.tar.gz'
pc_file = file(pc_file_name,'r')

#login to FTP server
ftp = FTP('ipaddress(or domain)')
ftp.login(user_id,passwd)

#send file
ftp.storbinary("STOR ",pc_file) #or ftp.storbinary("put ",pc_file)

#close connection and file
ftp.close()
pc_file.close()


homey 02-10-2004 11:41 PM

You are right! My first attempt was a bit lame. :(
So, I did some research and found a method that does work

Code:

#!/usr/bin/expect -f

#This works for mput, mget, put and get
#Make this file executable
#Run with the command: ./test  or whatever the file is called.

spawn ftp -i 192.168.0.1
expect "Name"
send "fred\r"
expect "Passsword:"
send "mypassword\r"
expect "rftp>"
send "cd /destination/directory\r"
expect "rftp>"
send "mput *.txt\r"
expect "rftp>"
exit



All times are GMT -5. The time now is 06:19 AM.