I have some files which need to be sftp from machine B ( linux ) to machine C. We need to start the task in machine A ( windows server 2003 ) and schedule this in Windows Scheduler. How can I do it?
I would do it interactively like this:
- ftp the files from machine A to machine B.
- telnet to machine B.
- with the telnet, sftp from machine B to machine C, put the files from machine B to machine C.
How can I do this with a script in machine A which is a windows? I can’t install any other software to help.
You mentioned ftp, telnet, and sftp. Those could be scripted via something like expect, or via some possibly complex script on A. However, you might be able to use this unix trick to do it all from A. You’ll need to be able to ssh from A to B, and from B to C. You’ll need identity authentication setup, so that a password is not required for those connections. (You could use agent forwarding of the identity on A for both connections.) Then run something like this on A:
That will move the file from A to C, via B, without storing the file on B.
I have done this sort of thing on windows before using the ssh and cat that is part of Cygwin. I don’t know how well it would work with other windows tools…
EDIT: I should have said a word to two about how that command works. The ssh program provides a pipe of sorts to move data back and forth between the local and remote machine. Normally, this pipe is connected to a shell on the remote end and it serves the same purpose as telnet, except with better security. However, this pipe can be used for anything. The sftp utility uses that pipe to move files around. The ssh command can take a command to execute on the remote system. For example,
ssh B lswould connect to B, run ls, and send the results back to you. What the above command does is ssh to B, and ask B to run an ssh connecting to C. That gives us a pipe from A, to B, to C. Now, what to do at both ends? Thecatprogram reads files and writes them to standard out. If no file names are given, it reads standard in. Thecat file-on-aread the file on theAmachine and writes it to thesshcommand. Thecat > file-on-creads the data sent to it and the> file-on-cpart (thanks to the shell) writes that to the filefile-on-c.Again, not sure if this is an option in your environment. Hope it helps.