Operating System - HP-UX
1834178 Members
2263 Online
110064 Solutions
New Discussion

File transfer from unix to windows

 
Michelle Barton
Frequent Advisor

File transfer from unix to windows

We need an automated way to transfer files (without encrypting userid and passwd) between our unix and windows servers, originating from Unix. Is anyone doing this? What are you using? Thanks!

Michelle
12 REPLIES 12
Luk Vandenbussche
Honored Contributor

Re: File transfer from unix to windows

Hi Michelle,

Put an ftp script in your crontab

This is an example of a script

ftp -nv hostname << EOF
user username password
bin
cd c:\temp
put /unixfile windowsfile
quit
EOF
Michelle Barton
Frequent Advisor

Re: File transfer from unix to windows

Thank you for your suggestion, but we do not want to include a username and password in a script.
TwoProc
Honored Contributor

Re: File transfer from unix to windows

You could create an sftp server on the Windows box, and then create ssh keys on the Unix box, then put those keys in the Windows box to allow the login.

I must confess though, I'm not sure how to create an sftp server on a Windows box (but I'd probably start by trying the free Cygwin tools). After that it's just an issue of standard setup of ssh keys. Cygwin for Windows can do that too.

Or... you could create a share point on a Windows server and use the CIFS client(Samba) to mount it onto the Unix box.
We are the people our parents warned us about --Jimmy Buffett
James R. Ferguson
Acclaimed Contributor

Re: File transfer from unix to windows

Hi Michelle:

If you don't want to embed a user and password in your FTP scripts, use a '$HOME/.netrc' file. See the manpages for 'netrc(4)' for more information.

Also, remember that if you are transfering an ASCII file from a UNIX to WINDOWS server, you need to force the translation of the UNIX newline to the Windows linefeed_carriage-return couplet. This is automatically done by FTP if you specify ASCII mode for the transfer.

Regards!

...JRF...
Oviwan
Honored Contributor

Re: File transfer from unix to windows

Hi

Perhaps you can find here something:
http://www.microsoft.com/windowsserversystem/sfu/default.mspx

check this for ftp "without" loggin:
http://www.informatik.uni-frankfurt.de/doc/man/hpux/netrc.4.html

otherwise you can use samba or nfs

Regards
Arturo Galbiati
Esteemed Contributor

Re: File transfer from unix to windows

Hi,
you could use the .netrc file in your directory to store all the windowd login in a file only, otherwise configure a windows frp anaonymous account.
HTH,
Art
Muthukumar_5
Honored Contributor

Re: File transfer from unix to windows

You do this by two way as,

1) .netrc file.

Create .netrc file with contents as,

Example:

The following is a valid entry for the host hpxdzg whose guest account
has the password sesame:

machine hpxdzg login guest password sesame

create the file in $HOME directory of the user which will transfer files.

2) Using ftp non-interactive method.

ftp -in <<-EOF
user username passwd
commands
bye
EOF

--
Muthu

Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: File transfer from unix to windows

You are transfering files between hetrogenous platforms, So try to use bin mode during transfer as,

ftp -in host <<-EOF
user username password
bin
..
..
..
bye
EOF

--
Muthu
Easy to suggest when don't know about the problem!
Darren Prior
Honored Contributor

Re: File transfer from unix to windows

Hi Michelle,

Have you considered using CIFS? You would need to share a drive from your Windows servers which would be mounted on the HP-UX server, then it would just be a case of copying files across as required.

regards,

Darren.
Calm down. It's only ones and zeros...
Michelle Barton
Frequent Advisor

Re: File transfer from unix to windows

I'd like more info on CIFS. I had heard that it set permissions to 777 on the files and required some weird security authentication before it could be used after a reboot. Thanks!
Darren Prior
Honored Contributor

Re: File transfer from unix to windows

The documentation for CIFS can be found here -> http://docs.hp.com/en/netcom.html#CIFS%20%28Common%20Internet%20File%20System%29

I'd suggest reading through the latest CIFS client guide to find out more how it could be integrated into your environment.

best regards,

Darren.
Calm down. It's only ones and zeros...
Cem Tugrul
Esteemed Contributor

Re: File transfer from unix to windows

Scripting FTP
Fred Mallett
A very common stumbling block people run into occurs when they try to have a script (or cron job) perform an ftp.
It would seem that something like:
ftp somehost <myloginname
mypassword
put somefile
bye
EOF
Would work, but due to stream handling on the part of ftp, it does not read from the document (or even an input redirected file), so you get prompted for the password, and the non-interactive session does not occur.
A fairly complex, but very powerful solution would be to learn the Expect language, and write some code in Perl or TCL, or some language that can include Expect. This is a good solution for dynamic situations.
If you want a quick and dirty (and less powerful) solution try using the .netrc file. IT is a reasonable thing to do when high security is not an issue (such as ftp's within a network, or a daily anonymous ftp get).
Here is the flow:
When ftp is invoked without the -n option, an autologin is attempted. Autologin occurs if:
â ¢ There is a .netrc file in the users home directory.
â ¢ That file is owned by the user running ftp
â ¢ The file has rights of 00 for group and others, with read rights for the owner (such as 600).
â ¢ There is a "machine" entry that matches the server argument on the command line.
For example, if you executed:
ftp host1
And you had a .netrc file with the following:
machine host1 login myaccount password mypassword
You would be automatically logged into host1. Normal prompting would occur for any other hostname (or IP address). Another allowed keyword is default, which you could use for various unlisted sites that allow anonymous logins.
Putting this together into the scripting scenario mentioned above, the following would now work in a shell script:
ftp host1 <bin
get somefile
bye
EOF
If you wanted to do an mget or mput, you could either use the -i option to ftp, or include the "prompt off" ftp command as seen in the Perl snippet below:
open(FTP, "|ftp host1>/dev/null");
print(FTP "prompt offn");
print(FTP "cd somedirn");
print(FTP "put somefilen");
print(FTP "byen");
close(FTP);
if ($?==0){
#do some success thing
} else {
#do some unsuccessful thing (log or email?)
}

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't