Operating System - Linux
1830172 Members
4575 Online
109999 Solutions
New Discussion

Re: I need a script to transfer a file via ftp from linux to windows server

 
SOLVED
Go to solution
'chris'
Super Advisor

I need a script to transfer a file via ftp from linux to windows server

hi

I need a script to transfer a file via ftp from linux to windows server.

If someone can post it, would be great.

kind regards
chris
10 REPLIES 10
Balaji N
Honored Contributor

Re: I need a script to transfer a file via ftp from linux to windows server

create a file called .netrc
put an entry like this.

machine macname login username password password.

then

ftp macname <ftp commands.
...
...
EOF

hth
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Thierry Poels_1
Honored Contributor

Re: I need a script to transfer a file via ftp from linux to windows server

hi,


ftp â v â n server << [EOT]
user username passwd
cd C:
cd /dir/dir
put filename
bye
[EOT]



good luck,
Th
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Thierry Poels_1
Honored Contributor

Re: I need a script to transfer a file via ftp from linux to windows server

hmm,

don't know where those characters come from :(

should be:

ftp -v -n server << [EOT]

-v : verbose
-n : no login (yet)

Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
'chris'
Super Advisor

Re: I need a script to transfer a file via ftp from linux to windows server

hi

thanks
I have other question.
additionally how to be notify by mail,
when the ftp
transfer was not seccessfully ?
can I do that with the same script ?

regards
chris

Thierry Poels_1
Honored Contributor
Solution

Re: I need a script to transfer a file via ftp from linux to windows server

Hi,

this is not straightforward as ftp always tend to return exit status 0.

You can redirect all output to a logfile and filter out "normal" text and mail the remaining.

something like:

LOG=/tmp/ftp$$.log
ftp -v -n server << [EOT] > $LOG 2>&1
...
grep -v "^220 " $LOG | grep -v "^331 " | grep -v "^230 " | grep -v "^250 " | grep -v "^200" | grep -v "^226" | grep -v "^150 " | grep -v "^120 " | grep -v "^221 " > /tmp/ftperr$$.log

if test -s /tmp/ftperr$$.log
then
mailx user < /tmp/ftperr$$.log
fi

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Stanimir
Trusted Contributor

Re: I need a script to transfer a file via ftp from linux to windows server

Here is something in Perl:
$ftpserver="192.168.200.72";
$username="stan";
$password="stan";
$remotedirectory="/home/stan";
$subdirectory="/home/stan";
$remotefilename="/home/stan/first.pl";
$ftp=Net::FTP->new($ftpserver);
$ftp->login($username,$password);
@remotefiles=$ftp->ls($remotedirectory);
$ftuse Net::FTP;
p->cwd($subdirectory);
$ftp->get($remotefilename);
$ftp->quit();
print "\nThe content of /home/stan - directory on $ftpserver:\n\n";
map {$_=$_."\n";print} @remotefiles;


Regards,Stan
'chris'
Super Advisor

Re: I need a script to transfer a file via ftp from linux to windows server

hi stan

and where can I put my mail address in your
perl script ?

I mean, if the ftp transfer was not successfully running,
I have to be notified by mail.

kind regards
chris
K.C. Chan
Trusted Contributor

Re: I need a script to transfer a file via ftp from linux to windows server

Just a thought. Have you thought of using samba?
Reputation of a thousand years can be determined by the conduct of an hour
'chris'
Super Advisor

Re: I need a script to transfer a file via ftp from linux to windows server

yes, but I need ftp
'chris'
Super Advisor

Re: I need a script to transfer a file via ftp from linux to windows server

I can't send files via samba shares
over internet !