Solved

Script to FTP files

Posted on 2012-04-02
12
573 Views
Last Modified: 2012-05-01
Need a script to FTP directories  from AIX box to windows. Both are at remote  locations.Has to keep the sub directories folder structure intact. Rsync and cygwin installed on windows.
0
Comment
Question by:raaj4354
[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
  • 6
  • 5
12 Comments
 
LVL 20

Accepted Solution

by:
carlmd earned 500 total points
ID: 37800359
#!/bin/ksh

COMO=/home/logs/rsync_log.`date +%d%h%y.%H:%M`
date | tee -a ${COMO}
print "rsynci script" | tee -a ${COMO}

cd /directory/onaix
rsync --delete -e rsh -av * remoteiporname:/remotepath/.
print "completed `date`" | tee -a ${COMO}

cd /directory2/onaix
rsync --delete -e rsh -av * remoteiporname:/remotepath2/.
print "completed `date`" | tee -a ${COMO}

print "Copy completed `date`" | tee -a ${COMO}
exit

This script will do the rsync copy, deleting files on the target that are gone from the source. It also creates a file /home/logs/... (you can change or remove this as desired) that has a copy of what happened. In this way if there is an issue you have someplace to look.

This script can be executed from a cron or using an "at" command. For example:
        at 6 pm today /etc/myrsyncscript

When creating the script on aix be sure to give it execute permission.

Note that you may need to include other options on the rsync line depending on how you have acces to the windows system setup.
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 37800606
So, do you want to run the script on the unix machine and "push" the files, or do you want to run it on the windows machine and "pull" the files?

~bp
0
 

Author Comment

by:raaj4354
ID: 37802662
carl: I executed the script above. seems to be a connectivity issue..
remote host refused an connection operation
rsync: connection unexpectedly  closed (o bytes transferred so far)
rsync error:error in rsync protocol data stream code (12) at io.c (600) ..any ideas..

Also  can the remote path on windows can be C:/some dir/..?


billprew:
I dont mind doing it either ways as long as it ftps the directories with all the files in it.
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 20

Expert Comment

by:carlmd
ID: 37803152
Ok, the issue is a login one.

rsync is configured to use ssh by default so lets replacing the line form above with this...

rsync --delete  -av * [user@]host::module/path/.
(the name/path you are putting in here is the same as you would to remote acceses a share)

This assumes you have ssh on the remote system.

This is detailed in the "-e" section of the doc at http://rsync.samba.org/ftp/rsync/rsync.html
0
 

Author Comment

by:raaj4354
ID: 37822044
Can the FTP done to a specific folder on windows rather than a shared folder. The script is failing since it not find the directory..!
0
 
LVL 20

Expert Comment

by:carlmd
ID: 37822962
Set up a top level share on the target system such as..
          myshare = \mycomputer\folder\folder2
and reference myshare in the login

You must have permission to log into the target system, and to write to the place where you want to put the file.
0
 

Author Comment

by:raaj4354
ID: 37894821
The files are being ftped out from the AIX when i see the log but i cant see the files on the windows side..!! Sorry for the late response.
0
 
LVL 20

Expert Comment

by:carlmd
ID: 37896180
My guess is that the share is not correct, or you are not using it.

Make a dummy file with some name that is unique. ftp that to the windows system and then search for it. That will tell you where they are going.
0
 

Author Comment

by:raaj4354
ID: 37910625
I made a dummy directory and executed  the script and I see the list of files that are uploading. My share folder is /new and in the script i gave /new/new1 and the log shows me "creating new directory /newnew1/ .  I searched the computer for folder newnew1 nothing found...
0
 
LVL 20

Expert Comment

by:carlmd
ID: 37910666
Just search for new1
0
 

Author Comment

by:raaj4354
ID: 37911575
#!/bin/ksh

COMO=/home/user/rsync_log.`date +%d%h%y.%H:%M`
date | tee -a ${COMO}
print "rsynci script" | tee -a ${COMO}

cd /usr/testdir/directory/subfolder/
rsync --delete -av * [user@]hostname:\new
print "completed `date`" | tee -a ${COMO}

print "Copy completed `date`" | tee -a ${COMO}
exit


I searched for directory name and the files that were transferred could not find any..:-(
I pinged the host to which i am trying ftp the files and it is reachable. Checked inside the shared folder no files ftped..
0
 
LVL 20

Expert Comment

by:carlmd
ID: 37914095
Just to be sure, you have replaced [user@]hostname with the real credentials that you would use to access that share?

like...

joe@192.168.1.10:/new
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

734 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