Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need a script to constant upload a file from one FTP server to another

Posted on 2009-12-20
16
Medium Priority
?
409 Views
Last Modified: 2013-12-26
Hi,

We have an Centos FTP server that has files uploaded to it from our database software. This file then needs to be uploaded to a 3rd companies FTP server under their account and \upload folder.

I have done this manually to test it and it works. How do I automate this in a script? I obviously need to do this via the cron jobs, I just cant get the syntax correct to get it working.

I need the linux ftp server to ftp to the IP, login as the user, browse to the \upload directory and then to a put {filename}. Is there anyone that can give me the correct syntax to do this?
0
Comment
Question by:Network_Padawan
  • 10
  • 4
  • 2
16 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 26093852
please see my answer # 21449603 in the link below

http://www.experts-exchange.com/OS/Linux/Q_23357010.html
0
 
LVL 10

Assisted Solution

by:nabeelmoidu
nabeelmoidu earned 500 total points
ID: 26093863
0
 

Author Comment

by:Network_Padawan
ID: 26100715
Thanks. I can log into the ftp server as advised, however I can not browse to the upload directory to transfer the file,

I created a file called ipndftp.sh
chmod +X ipndftp.sh

vi .netrc

ftp {servername}
login {username}
password {password}

vi ipndftp.sh
ftp {sername}
cd /upload

Doesnt browse to the upload directory, I type ls once in there and I can see the upload directory
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Network_Padawan
ID: 26100718
Hey Nabeel thanks for that, do i need to install perl to get the code to work?
0
 

Author Comment

by:Network_Padawan
ID: 26101212
Hi Nabeel ive done the perl script:

Please see....


#!/usr/bin/perl
use Net::FTP;

my $host="192.168.X.X";
my $directory="upload";

$ftp=Net::FTP->new($host,Timeout=>240) or $newerr=1;
push @ERRORS,"Can't ftp to $host:$! \n" if $newerr;
myerr() if $newerr;
print "Connected \n";

$ftp->login("username","password") or $newerr;
$ftp->cwd('/upload');
print "Getting file list";
push @ERRORS, "Can't ftp to $host:$! \n" if $newerr;
$ftp->quit if $newerr;
print "Logged in \n";

$ftp->binary;
$ftp->wput("IPNDUPGLOGO*.*");
$ftp->quit;

Open in new window

0
 

Author Comment

by:Network_Padawan
ID: 26101223
I get the following error with the script above....

Can't locate object method "wput" via package "Net::FTP" at .........


0
 

Author Comment

by:Network_Padawan
ID: 26101984
Ok please ignore all of the above, I almost have it working with the following script I assembled....
#!/usr/bin/perl

use Net::FTP;
my $hostname = "192.168.37.5";
my $destdir = "upload";
my $user =  "tglogodp";
my $password = "28iO9fX?";

#chdir($destdir);
my @files=<IPNDUPGLOGO.*>;
my $ftp = Net::FTP->new($hostname, Debug => 0) or die "Cannot connect to $hostname: $@";
$ftp->login($user,$pass) or die "Cannot login", $ftp->message;
   chdir($destdir) or die "Can't chdir to $destdir $!";
   foreach (@files) {
     $ftp->put($_) or warn "put failed ",$ftp->message;
  }

$ftp->quit;

Open in new window

0
 

Author Comment

by:Network_Padawan
ID: 26102006
The only part I can not get working is the chdir part...it wont change the path to the "upload" path. If i can get that working than this script works.
0
 
LVL 10

Expert Comment

by:nabeelmoidu
ID: 26102212
use $ftp->cwd instead of chdir.
0
 

Author Comment

by:Network_Padawan
ID: 26102223
no doesnt work. This command seems to only change the path on the source linux box, that is the box I am running the script on. I need to be able to "put" a heap of files in the download and upload directory on the target ftp server.

FYI, when I remote manually to the FTP server, I am placed before the upload and download directory. These two folders are the ones I need to put files into.

Is there a better way?
0
 
LVL 10

Expert Comment

by:nabeelmoidu
ID: 26102356
cwd changes directory on the server not client.
can you post your output logs here ? what ftp server are you using?

can you chdir through normal login to the upload directory?


0
 

Author Comment

by:Network_Padawan
ID: 26102412
I am running vsftp on centos 5.3.

No I can not do "chdir upload", it does not understand the chdir command. It only understand cd upload.

0
 

Author Comment

by:Network_Padawan
ID: 26102414
Though I though chdir was purely a perl command.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 26102562
what did not work in the provided procedure / script?
0
 
LVL 10

Expert Comment

by:nabeelmoidu
ID: 26103043
Set your vsftpd.conf to these paramenters

http://nmkuttiady.blogspot.com/2007/08/ftp-troubles.html

and post the error log (or you can easily analyze yourself)
0
 

Author Closing Comment

by:Network_Padawan
ID: 31668408
Okay the perl script finally worked. Just had to tinker with the order of the commands.

Thanks guys.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The article explains the protocols and technology which is involved when two computers on different TCP/IP networks communicate with each other. In the diagram, a router is used to segregate two networks. The networks are 192.168.1.0/24 and 192…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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