Solved

Automatically ftp from unix to windows

Posted on 2004-03-26
12
2,200 Views
Last Modified: 2013-12-26
Can sommeone tell me how can i automatically ftp from unix session to windows machine. i write manually
ftp "win name"
Please inter your name: "user_name"
user name okay, Need password.
Password: "password"
user logged in.
ftp>
0
Comment
Question by:sBahman
12 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 10685709
Use curl or wget that makes live a bit easier
curl -user-name:password ftp://ftp.server/file_you_want_to_get

Regards
Friedrich
0
 

Expert Comment

by:NeerajaR
ID: 10685971
Am not sure if this is what is expected.

Can be acheived by writing a script something like below
ftp  ${MACHINE_NAME} << [[
        ascii
       cd ${SRC_DIR}
        lcd ${DES_DIR}
        get ${filename}
        bye
[[
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10685997
Hi sBahman,
You can define host,user and password entries in the .netrc file. Check the netrc man page:

machine ray login demo password mypassword macdef init
lcd <local dir>
cd <remote dir>
put ...

Make sure your .netrc is not readable by other users:
chmod og-rwx ~/.netrc



Cheers,

Stefan
0
 

Author Comment

by:sBahman
ID: 10686539
i create a .netrc file but this one give me a error
Macro definition missing null line terminator.
221 Goodbye.  Control connection closed.
0
 

Author Comment

by:sBahman
ID: 10686811
now working!. But i don't undrestand how can i do it remotly i need to say
lcd "lname"
cd "rname"
put "fname"
0
 
LVL 1

Expert Comment

by:mdhmi
ID: 10707530

Example:

ftp -nv << EOF
 open 192.168.10
   user niceguy yourpasswd
   bin
   cd /tmp
   put testfile.tmp
   bye
EOF

Mark
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:stefan73
ID: 10713324
sBahman,
> Macro definition missing null line terminator.

That's an empty line.

> i don't undrestand how can i do it remotly i need to say
Normally, the .netrc driven FTP jobs are only for very simple tasks. If you really want to, you could write a Perl script which sets up the .netrc, starts the FTP and restores the old .netrc.

You'd be better off with a more sophisticated FTP client, such as ncftp (but sometimes system restrictions don't allow it):

http://www.ncftp.com/

Stefan
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10713341
mdhmi,
>  user niceguy yourpasswd

That's the pain... cleartext passwords are not good. It's too easy to forget using chmod 700 on your script.

In case you are even moderately sensitive to security issues, consider using SSH (scp/sftp) with public key authentication instead of FTP.

Stefan
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 10729239
Just wanted to stress that if the permissions are not set correctly on .netrc, automatic ftp will not work.
0
 
LVL 11

Accepted Solution

by:
avizit earned 20 total points
ID: 10930280
seems like a job for "expect" scripts

you need to have expect installed though

 basically you can have a script like following

#!/usr/bin/expect --
set timeout 20
spawn ftp yourhost.com
expect "login:"
send "yourusername\r"
expect "Password:"
send "yourpasword\r"
interact


/abhijit/

ftp "win name"
Please inter your name: "user_name"
user name okay, Need password.
Password: "password"
user logged in.
ftp>
0
 

Expert Comment

by:swiercm
ID: 11283935
If you are using the .netrc file you will need to add the following lines in it.
Assuming you know "vi".

machine <IP address or DNS name>
               login <you login id for the server your ftping to>
               password <the password for the above id>

macdef    <some_name_anything>
               put <the_filename_you_want_to_ftp>
               quit

Now that is all the .netrc needs to ftp to another server.
BTW the "<" and ">" are not in the code.

Now the tricky stuff to run the ftp.
You need to make up another script and in it you'll have the following:
echo "\$ <some_name_anything>" | ftp -v <IP address or DNS name>

Make sure you use the quotes.
You can set up the script to run in cronjob or at job at a certain time each day. In addition you can send the out put to a log file and check for a successful transmission.
Doing it via the .netrc you can send to multiple servers and have multiple macdefs, all automatically no manual intervention.
0
 

Author Comment

by:sBahman
ID: 11286765
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 163
VB.NET how to use the Vertical ScrollBar 5 90
changeXy challenge 13 68
JQuery serialize and unserialize 8 51
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now