Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to FTP files with a bash script

Posted on 2008-10-31
4
Medium Priority
?
615 Views
Last Modified: 2013-12-26
I am making a bash shell script that should look for files in a directory then upload them to an ftp server and move the original file to another directory.

It should ftp then move all files until the folder is empty and then wait 5 minutes before looking for new files.

I understand how to do everything except actually ftp the files to another server.

How do I make this pseudocode into a bash script?
***      ftp movie file to server domain.com with id "login" password "password"


#!/bin/bash
while true ; do
for movie in /home/smartdata/www/html/files/encoded/mp4/widescreen16x9/*.* ; do
***	ftp movie file to server domain.com with id "login" password "password"
    NEWPATH=/home/smartdata/www/html/files/encoded/mp4/uploaded/"$movie"
mv /home/smartdata/www/files/encoded/mp4/"$movie" $NEWPATH
done
echo Waiting 5 minutes
sleep 300 #wait 5 min
done

Open in new window

0
Comment
Question by:toben88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 22854667
here the ftp part:

ftp remoteserver <<-END
cd /dir
binary
put filename
bye
END

- For ftp to work without providing any username / password,  use .netrc file in the user's home directory (the one who will run the script). This file should not be readable by others i.e. use
chmod 400 .netrc

The entry in .netrc should be as below:

machine remoteserver
login remoteusername
password mypassword

remoteserver is the server which is the ftp server where you want to sent the file(s)
remoteusername is the remote user login name on the ftp server
mypassword is the password of the remote user on the ftp server

for more info about .netrc, please use man netrc
0
 
LVL 20

Expert Comment

by:edster9999
ID: 22871855
ftp is not secure - especially if you are putting your passwords into files.

if you have an SSH server on the same box you can use the SCP command.  It is as simple as copy command.

for format is similar to :
scp file1.txt servername:/home/user/file1.txt

in the script you could do something like :
scp $filename $remotehost:$path/$filename
0
 
LVL 20

Expert Comment

by:edster9999
ID: 22871858
Oh - I forgot to say - if you dont want prompts for passwords you'll need to set up ssh keys
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question