LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2004, 01:48 PM   #1
dlm4444
Member
 
Registered: Sep 2003
Posts: 30

Rep: Reputation: 15
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
 
Old 02-10-2004, 02:39 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

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

Last edited by homey; 02-10-2004 at 02:47 PM.
 
Old 02-10-2004, 03:03 PM   #3
dlm4444
Member
 
Registered: Sep 2003
Posts: 30

Original Poster
Rep: Reputation: 15
thanks, but the script didn't help much.

Is there a way for autologin through ftp?
 
Old 02-10-2004, 03:09 PM   #4
Linux_in_NH
Member
 
Registered: Jan 2004
Location: NH
Distribution: Mandrake, Geentoo, Ubuntu
Posts: 105

Rep: Reputation: 15
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.
 
Old 02-10-2004, 03:11 PM   #5
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Rep: Reputation: 15
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()
 
Old 02-10-2004, 11:41 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

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

Last edited by homey; 02-10-2004 at 11:44 PM.
 
  


Reply



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
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 06:57 PM
where i could get freespace script for my FTP RINO2004 Linux - Software 1 08-27-2004 07:04 AM
Problem with FTP Script bmeckle Linux - General 1 07-22-2004 02:28 PM
Ftp script scialom Linux - Software 2 05-04-2004 03:03 PM
FTP script Veteq Programming 3 04-21-2004 12:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:38 PM.

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