Help with a script to transfer files from Solaris to windows

Hi

Please can you tell me what could be wrong with the following script to transfer files from solaris 10 to windows machine:

#!/bin/sh
HOST=<IP>
USER=administrator
PASSWD=xyz123zyx


/usr/bin/ftp -inv  <<EOF
connect $HOST
user $USER $PASSWD
cd Documents
binary
mput *.sh
bye
EOF

A bit more info might be appreciated, e.g. strange/inadequate/unexpected behaviour or error messages.

does not give me anything at all, strange....
This windows machine is on a domain, does it matter?
I try to use in the line :

USER=\prtg_svr\administrator

but with no luck

The windows machine must be configured as a ftp server which Windows boxes aren't by default.

That doesn't help too much. I don't think above will be a valid user on either system, on top of, on *nix systems, the back slashes if not quoted work a escape chars yielding USER=prtg_svradministrator .
Please approach the problem stepwise:

  • does it connect?
  • does it log in?
  • does it change the directory?
    etc. etc.

The first thing to do is to transfer a file using ftp manually from the command line. If that doesn't work then you've got no chance trying to script it.

the windows server is configured as ftp server
if I run from command prompt ftp -inv <ip address> it does connect, but does not login:

 ftp -inv 10.100.48.116
Connected to 10.100.48.116.
220-FileZilla Server version 0.9.44 beta
220-written by Tim Kosse (tim.kosse@filezilla-project.org)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
ftp>

"Remote system is type UNIX" tells me you're doing this from the Windows box. Yes, by default a Windows box usually has a ftp client installed but to accept inbound ftp connections the Windows box needs to be a ftp server.

I think we all assume that, since you are posting on a Unix forum here, you are trying to connect from a Unix box to a windows box. Yes??

Yes I am trying to connect from UNIX to WINDOWS and I have filezilla server installed on it

Right, so before you try and script anything, login as whatever user, and check the infrastructure is in place to support the ftp by invoking ftp from your command line and sending a file over to windows.

First of all don't put your password in a script! Use the $HOME/.netrc file, which has the format:

machine <dns or ip address> login <username> password <password>

one machine per line. Now you can get rid of the password in the script. You are also able to change permissions on this file so that only you can read it. As been said earlier, test with manual FTP connections and modify the script accordingly. With my suggestion of using the .netrc file the invocation of ftp will be as follows:

ftp ${HOST} << EOF

Andrew

from command line:

ftp -inv 10.100.48.116
Connected to 10.100.48.116.
220-FileZilla Server version 0.9.44 beta
220-written by Tim Kosse (tim.kosse@filezilla-project.org)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
ftp> put ftpfiles.sh
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
ftp> by
221 Goodbye

or :

 ftp -inv 10.100.48.116
Connected to 10.100.48.116.
220-FileZilla Server version 0.9.44 beta
220-written by Tim Kosse (tim.kosse@filezilla-project.org)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
ftp> user
(username) administrator
331 Password required for administrator
Password:
530 Login or password incorrect!
Login failed.
ftp>

but the credentials are correct, please beleive me

If you're doing this on the Unix box and it's connecting to a Windows box why does it say "Remote system is type UNIX"?
I'd expect to see "Remote system is Windows".

Anybody know why that would happen?

I stumbled across this as well, but it might be part of the welcome message emitted by filezilla on the windows server.

Is the user blacklisted in filezilla on the windows system? Or, does he/she need to be whitelisted? Did you try another user or even anonymous login?

1 Like

I've just downloaded the latest filezilla server onto my Windows box and yes it says Remote system type is UNIX. Looking at the filezilla console you get the message 215 UNIX emulated by FileZilla . Mystery solved?

Stupid question directed at original poster: Did you set up any users within the filezilla server? Using your windows accounts will not work. You have to add username/password/home directory to filezilla.

Andrew

1 Like

Hi

I have used the following on a different server:

 ftp 192.168.1.19
Connected to 192.168.1.19.
220 Microsoft FTP Service
Name (192.168.1.19:root): emm
331 Password required for emm.
Password:
230 User emm logged in.
Remote system type is Windows_NT.
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for file list.
CHARGINGSYSTEM
GGSN
SGSN
SMSC
SMSGw
exodus.241115
software
226 Transfer complete.
66 bytes received in 0.00017 seconds (382.51 Kbytes/s)
ftp> put collect.sh
200 PORT command successful.
150 Opening ASCII mode data connection for collect.sh.
226 Transfer complete.
local: collect.sh remote: collect.sh
1288 bytes sent in 0.009 seconds (140.27 Kbytes/s)
ftp> by
221

So it worked

But on the very same server using the script:

#!/bin/sh
HOST=192.168.1.19
USER=emm
PASSWD=emm
#printf "PASSWD is $PASSWD \n

/usr/bin/ftp -inv  <<EOF
connect $HOST
user $USER $PASSWD

binary
mput *.sh
bye
EOF

the result is:

./ftpfiles.sh
?Invalid command
Not connected.
Not connected.
Not connected.

As apmcd47 has already said, don't try to put userid/passwd credentials in the script. Put a .netrc file in the home directory under which the script is running. As already said, make sure you get the access rights set read-only for the owner.

Once you've done that typing ftp <hostname> from the command line should just connect instantly.

my home directory of my unix server does not have that file! Should I create?

 echo $HOME
/moneta_home
bash-3.00$ ls -al
total 6
drwxr-xr-x   2 root     root         512 May 27  2011 .
drwxr-xr-x  80 root     root        2048 Aug 15 10:12 ..
You have new mail in /var/mail/moneta
bash-3.00$

Yes, create a file called .netrc in your home directory.

Put one line in it like this:

machine <ftp target name> login <remote login user> password <password>

Set the file so you own it, and with your main group
Set the mask to 600

Make sure the ftp target name also appears in /etc/hosts with its correct ip address.

Then, when you run "ftp <nodename>" it will look up the name in /etc/hosts to get the ip address, then look for .netrc and if the target node is listed it will use the userid and password from there to connect via ftp. It should just connect instantly without asking for credentials.

None of the above requires a reboot.

this is what I did:

echo $HOME/.netrc
//.netrc
You have new mail in /var/mail/root
root@moneta # ls -al .netrc
.netrc: No such file or directory
root@moneta #

them vi:

machine 192.168.1.19 login emm password emm

them:

chmod 0600 ~/.netrc

them tested:

ftp 192.168.1.19
Connected to 192.168.1.19.
220 Microsoft FTP Service
331 Password required for emm.
230 User emm logged in.
Remote system type is Windows_NT.
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for file list.
CHARGINGSYSTEM
GGSN
SGSN
SMSC
SMSGw
collect.sh
exodus.241115
software
226 Transfer complete.
78 bytes received in 0.00048 seconds (159.66 Kbytes/s)
ftp> put vmstat.dat
200 PORT command successful.
150 Opening ASCII mode data connection for vmstat.dat.
226 Transfer complete.
local: vmstat.dat remote: vmstat.dat
8111 bytes sent in 0.016 seconds (507.89 Kbytes/s)
ftp> by
221

them using the script:

#!/bin/sh
HOST=192.168.1.19

/usr/bin/ftp -inv  <<EOF
connect $HOST
user $USER $PASSWD

binary
mput *.sh
bye
EOF

them the error:

./ftpfiles.sh
?Invalid command
Not connected.
Not connected.
Not connected.
You have new mail in /var/mail/root
root@moneta #

using command line works, does not work on the script