2

I want to automate the process of copy a file from Windows FTP location to a Unix box from my Windows 7 machine.

I have managed to search the net and succeed to the point of connecting to the Unix box using SSH and PuTTY.

The input file to PuTTY contains the commands, but it stops at password and I couldn't find a way to overcome this.

To do this I have a created a batch file, so I can schedule a Windows job on my Windows 7 machine to start copy a file everyday from the Windows FTP server (other Windows machine not mine) to the Unix box.

Batch file:

putty -ssh lxdsdsp0  -l "user_1" -pw "mypass" -m "D:\cmd.txt" -t

My cmd.txt

cd /x06/scratch-data/ 
ftp domain\user_1@winapp67.sr.dv.com
mypass
/bin/bash

When I execute my batch file, it logs in to the Unix box through SSH and types the commands but stops when I have my password as input file in the PuTTY cmd.txt file.

Please help.

Using username "user_1".

Welcome to SuSE Linux Enterprise Server 9 (x86_64)

Connected to domain\user_1@winapp67.sr.dv.com.
220 Microsoft FTP Service
331 Password required for domain\user_1.
Password:
530 User domain\user_1 cannot log in.
ftp: Login failed.
ftp>
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
coolcake
  • 2,917
  • 8
  • 42
  • 57
  • why dont you just automate the process of copying the file directly from the windows server to the unix machine? Why you need to use a third computer for the automation of doing something in between two other machines? – nouseforname Mar 22 '16 at 05:41

1 Answers1

1

The contents of the cmd.txt is executed by a remote shell line-by-line. The contents is not used, as if you typed those commands on your keyboard.

So the shell executes the ftp and waits for it to exit, before it proceeds to the mypass line (eventually trying to execute it and failing as it is not a recognized shell command).

What you can do, is to use Plink instead of PuTTY. The Plink in a tool from PuTTY package intended for automation (PuTTY is not). It is a console application. As such, you can redirect its input from your cmd.txt. The contents will then be used as if you typed those commands on your keyboard.

plink.exe -ssh lxdsdsp0 -l "user_1" -pw "mypass" -t < D:\cmd.txt

See also How to pass user input automatically using plink.exe

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992