Index: atomicio.cpp
===================================================================
--- atomicio.cpp	(revision 883883)
+++ atomicio.cpp	(working copy)
@@ -22,7 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
+#ifndef Q_WS_WIN
 //#include "includes.h"
 //RCSID("$OpenBSD: atomicio.c,v 1.9 2001/03/02 18:54:30 deraadt Exp $");
 
@@ -65,3 +65,4 @@
 	}
 	return (pos);
 }
+#endif //Q_WS_WIN
Index: ksshprocess.cpp
===================================================================
--- ksshprocess.cpp	(revision 883883)
+++ ksshprocess.cpp	(working copy)
@@ -85,67 +85,78 @@
 QRegExp KSshProcess::versionStrs[] = {
     QRegExp("OpenSSH_3\\.[6-9]|OpenSSH_[1-9]*[4-9]\\.[0-9]"),
     QRegExp("OpenSSH"),
-    QRegExp("SSH Secure Shell")
+    QRegExp("SSH Secure Shell"),
+    QRegExp("plink: Release")
 };
 
 const char * const KSshProcess::passwordPrompt[] = {
     "password:", // OpenSSH
     "password:", // OpenSSH
-    "password:"  // SSH
+    "password:",  // SSH
+    "password:",  // putty
 };
 
 const char * const KSshProcess::passphrasePrompt[] = {
     "Enter passphrase for key",
     "Enter passphrase for key",
-    "Passphrase for key"
+    "Passphrase for key",
+    "???"
 };
 
 const char * const KSshProcess::authSuccessMsg[] = {
     "Authentication succeeded",
     "ssh-userauth2 successful",
-    "Received SSH_CROSS_AUTHENTICATED packet"
+    "Received SSH_CROSS_AUTHENTICATED packet",
+    "Started a shell/command"
 };
 
 const char* const KSshProcess::authFailedMsg[] = {
     "Permission denied (",
     "Permission denied (",
-    "Authentication failed."
+    "Authentication failed.",
+    "Access denied"
 };
 
 const char* const KSshProcess::tryAgainMsg[] = {
     "please try again",
     "please try again",
-    "adjfhjsdhfdsjfsjdfhuefeufeuefe"
+    "adjfhjsdhfdsjfsjdfhuefeufeuefe",
+    "???"
 };
 
 QRegExp KSshProcess::hostKeyMissingMsg[] = {
     QRegExp("The authenticity of host|No (DSA|RSA) host key is known for"),
     QRegExp("The authenticity of host|No (DSA|RSA) host key is known for"),
-    QRegExp("Host key not found from database")
+    QRegExp("Host key not found from database"),
+    QRegExp("???")
 };
 
 const char* const KSshProcess::continuePrompt[] = {
     "Are you sure you want to continue connecting (yes/no)?",
     "Are you sure you want to continue connecting (yes/no)?",
-    "Are you sure you want to continue connecting (yes/no)?"
+    "Are you sure you want to continue connecting (yes/no)?",
+    "???"
 };
 
 const char* const KSshProcess::hostKeyChangedMsg[] = {
     "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!",
     "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!",
-    "WARNING: HOST IDENTIFICATION HAS CHANGED!"
+    "WARNING: HOST IDENTIFICATION HAS CHANGED!",
+    "???"
 };
 
 QRegExp KSshProcess::keyFingerprintMsg[] = {
     QRegExp("..(:..){15}"),
     QRegExp("..(:..){15}"),
-    QRegExp(".....(-.....){10}")
+    QRegExp(".....(-.....){10}"),
+    QRegExp("???")
 };
 
 QRegExp KSshProcess::knownHostsFileMsg[] = {
     QRegExp("Add correct host key in (.*) to get rid of this message."),
     QRegExp("Add correct host key in (.*) to get rid of this message."),
-    QRegExp("Add correct host key to \"(.*)\"")
+    QRegExp("Add correct host key to \"(.*)\""),
+    QRegExp("???")
 };
 
 
@@ -153,7 +164,8 @@
 const char* const KSshProcess::changeHostKeyOnDiskPrompt[] = {
     "as;jf;sajkfdslkfjas;dfjdsa;fj;dsajfdsajf",
     "as;jf;sajkfdslkfjas;dfjdsa;fj;dsajfdsajf",
-    "Do you want to change the host key on disk (yes/no)?"
+    "Do you want to change the host key on disk (yes/no)?",
+    "???"
 };
 
 // We need this in addition the authFailedMsg because when
@@ -167,13 +179,15 @@
 QRegExp KSshProcess::hostKeyVerifyFailedMsg[] = {
     QRegExp("Host key verification failed\\."),
     QRegExp("Host key verification failed\\."),
-    QRegExp("Disconnected; key exchange or algorithm? negotiation failed \\(Key exchange failed\\.\\)\\.")
+    QRegExp("Disconnected; key exchange or algorithm? negotiation failed \\(Key exchange failed\\.\\)\\."),
+    QRegExp("???")
 };
 
 const char * const KSshProcess::connectionClosedMsg[] = {
     "Connection closed by remote host",
     "Connection closed by remote host",
-    "Connection closed by remote host"
+    "Connection closed by remote host",
+    "???"
 };
 
 
@@ -185,6 +199,7 @@
 }
 
 void KSshProcess::installSignalHandlers() {
+#ifndef Q_WS_WIN
     struct sigaction act;
     memset(&act,0,sizeof(act));
     act.sa_handler = SIGCHLD_handler;
@@ -197,19 +212,26 @@
 #endif
 	    ;
     sigaction(SIGCHLD,&act,NULL);
+#endif
 }
 					
 void KSshProcess::removeSignalHandlers() {
+#ifndef Q_WS_WIN
 	struct sigaction act;
 	memset(&act,0,sizeof(act));
 	act.sa_handler = SIG_DFL;
 	sigaction(SIGCHLD,&act,NULL);
+#endif
 }
 
 KSshProcess::KSshProcess() 
             : mVersion(UNKNOWN_VER), mConnected(false), 
         mRunning(false), mConnectState(0) {
+#ifndef Q_WS_WIN
     mSshPath = KStandardDirs::findExe(QString::fromLatin1("ssh"));
+#else
+    mSshPath = KStandardDirs::findExe(QString::fromLatin1("plink"));
+#endif
     kDebug(KSSHPROC) << "KSshProcess::KSshProcess(): ssh path [" << 
 		mSshPath << "]" << endl;
         
@@ -303,6 +325,15 @@
 
 bool KSshProcess::setOptions(const SshOptList& opts) {
     kDebug(KSSHPROC) << "KSshProcess::setOptions()";
+
+	if( mVersion == UNKNOWN_VER ) {
+        // we don't know the ssh version yet, so find out
+        version();
+        if( mVersion == UNKNOWN_VER ) {
+            return false;
+        }
+    }
+
     mArgs.clear();
     SshOptListConstIterator it;
     QString cmd, subsystem;
@@ -322,7 +353,11 @@
             break;
 
         case SSH_PORT:
-            mArgs.append("-p");
+            if( mVersion == PLINK ) {
+                mArgs.append("-P");
+            } else {
+                mArgs.append("-p");
+            }
             tmp.setNum((*it).num);
             mArgs.append(tmp);
             mPort = (*it).num;
@@ -349,7 +384,7 @@
                 mArgs.append("-o");
                 mArgs.append(tmp);
             }
-            else if( mVersion <= SSH ) {
+            else if( mVersion <= SSH || mVersion == PLINK ) {
                 if( (*it).num == 1 ) {
                     mArgs.append("-1");
                 }
@@ -358,42 +393,54 @@
             break;
 
         case SSH_FORWARDX11:
-            tmp = "ForwardX11=";
-            tmp += (*it).boolean ? "yes" : "no";
-            mArgs.append("-o");
-            mArgs.append(tmp);
+            if( mVersion == PLINK) {
+                mArgs.append((*it).boolean ? "-X" : "-x");
+            } else {
+                tmp = "ForwardX11=";
+                tmp += (*it).boolean ? "yes" : "no";
+                mArgs.append("-o");
+                mArgs.append(tmp);
+            }
             break;
 
         case SSH_FORWARDAGENT:
-            tmp = "ForwardAgent=";
-            tmp += (*it).boolean ? "yes" : "no";
-            mArgs.append("-o");
-            mArgs.append(tmp);
+            if( mVersion == PLINK) {
+                mArgs.append((*it).boolean ? "-A" : "-a");
+            } else {
+                tmp = "ForwardAgent=";
+                tmp += (*it).boolean ? "yes" : "no";
+                mArgs.append("-o");
+                mArgs.append(tmp);
+            }
             break;
 
         case SSH_ESCAPE_CHAR:
-            if( (*it).num == -1 )
-                tmp = "none";
-            else
-                tmp = QByteArray( (char)((*it).num), '\0' );
-            mArgs.append("-e");
-            mArgs.append(tmp);
+            if( mVersion != PLINK ) {
+                if( (*it).num == -1 )
+                    tmp = "none";
+                else
+                    tmp = QByteArray( (char)((*it).num), '\0' );
+                mArgs.append("-e");
+                mArgs.append(tmp);
+            }
             break;
 
         case SSH_OPTION:
             // don't allow NumberOfPasswordPrompts or StrictHostKeyChecking
             // since KSshProcess depends on specific setting of these for 
             // preforming authentication correctly.
-            tmp = (*it).str.toLatin1();
-            if( tmp.contains("NumberOfPasswordPrompts") ||
-                tmp.contains("StrictHostKeyChecking") ) {
-                mError = ERR_INVALID_OPT;
-                return false;
+            if( mVersion != PLINK ) {
+                tmp = (*it).str.toLatin1();
+                if( tmp.contains("NumberOfPasswordPrompts") ||
+                    tmp.contains("StrictHostKeyChecking") ) {
+                    mError = ERR_INVALID_OPT;
+                    return false;
+                }
+                else {
+                    mArgs.append("-o");
+                    mArgs.append(tmp);
+                }
             }
-            else {
-                mArgs.append("-o");
-                mArgs.append(tmp);
-            }
             break;
             
         case SSH_COMMAND:
@@ -552,6 +599,9 @@
 }
 
 QString KSshProcess::getLine() {
+#ifdef Q_WS_WIN
+    return ssh.readLineFromPty(false);
+#else
     static QStringList buffer;
     QString line = QString();
     QByteArray ptyLine, errLine;
@@ -669,6 +719,7 @@
     
 
     return line;
+#endif
 }
 
 // All the different states we could go through while trying to connect.
Index: atomicio.h
===================================================================
--- atomicio.h	(revision 883883)
+++ atomicio.h	(working copy)
@@ -1,6 +1,8 @@
 #ifndef atomicio_h
 #define atomicio_h
 
+#ifndef Q_WS_WIN
+
 /*	$OpenBSD: atomicio.h,v 1.3 2001/03/02 18:54:30 deraadt Exp $	*/
 
 /*
@@ -36,4 +38,6 @@
  */
 ssize_t	atomicio(int fd, char *_s, size_t n, bool read = true);
 
+#endif //Q_WS_WIN
+
 #endif
Index: ksshprocess.h
===================================================================
--- ksshprocess.h	(revision 883883)
+++ ksshprocess.h	(working copy)
@@ -137,6 +137,7 @@
 	OPENSSH_3_6,
         OPENSSH,
         SSH,
+        PLINK,
         SSH_VER_MAX,
         UNKNOWN_VER
     };	
@@ -503,7 +504,11 @@
      *
      * @return The file descriptor of pty to which ssh is attached.
      */
+#ifndef Q_WS_WIN
     int pty() { return ssh.fd(); }
+#else
+    KProcess *pty() { return ssh.fd(); }
+#endif
 private:
     /**
      * Path to the ssh binary.
Index: kio_sftp.cpp
===================================================================
--- kio_sftp.cpp	(revision 883883)
+++ kio_sftp.cpp	(working copy)
@@ -132,12 +132,16 @@
 sftpProtocol::sftpProtocol(const QByteArray &pool_socket, const QByteArray &app_socket)
              : SlaveBase("kio_sftp", pool_socket, app_socket),
                   mConnected(false), mPort(-1), mMsgId(0) {
+#ifndef Q_WS_WIN
   kDebug(KIO_SFTP_DB) << "sftpProtocol(): pid = " << getpid();
+#endif
 }
 
 
 sftpProtocol::~sftpProtocol() {
+#ifndef Q_WS_WIN
     kDebug(KIO_SFTP_DB) << "~sftpProtocol(): pid = " << getpid();
+#endif
     closeConnection();
 }
 
@@ -1574,9 +1578,15 @@
 bool sftpProtocol::getPacket(QByteArray& msg) {
     QByteArray buf(4096, '\0');
 
+#ifdef Q_WS_WIN
+    ssize_t len;
+    if(ssh.pty()->waitForReadyRead(2000)) {
+        len = ssh.pty()->read(buf.data(), 4);
+    }
+#else
     // Get the message length...
     ssize_t len = atomicio(ssh.stdioFd(), buf.data(), 4, true /*read*/);
-
+#endif
     if( len == 0 || len == -1 ) {
         kDebug(KIO_SFTP_DB) << "getPacket(): read of packet length failed, ret = "
                              << len << ", error =" << strerror(errno) << endl;
@@ -1598,7 +1608,11 @@
     b.open( QIODevice::WriteOnly );
 
     while( msgLen ) {
+#ifdef Q_WS_WIN
+        len = ssh.pty()->read(buf.data(), qMin(buf.size(), msgLen));
+#else
         len = atomicio(ssh.stdioFd(), buf.data(), qMin(buf.size(), msgLen), true /*read*/);
+#endif
 
         if( len == 0 || len == -1) {
             QString errmsg;
@@ -1631,7 +1645,11 @@
 bool sftpProtocol::putPacket(QByteArray& p){
 //    kDebug(KIO_SFTP_DB) << "putPacket(): size == " << p.size();
     int ret;
+#ifdef Q_WS_WIN
+    ret = ssh.pty()->write(p.data(), p.size());
+#else
     ret = atomicio(ssh.stdioFd(), p.data(), p.size(), false /*write*/);
+#endif
     if( ret <= 0 ) {
         kDebug(KIO_SFTP_DB) << "putPacket(): write failed, ret =" << ret <<
             ", error = " << strerror(errno) << endl;
Index: process.cpp
===================================================================
--- process.cpp	(revision 883883)
+++ process.cpp	(working copy)
@@ -26,7 +26,10 @@
 #include <signal.h>
 #include <errno.h>
 #include <string.h>
+
+#ifndef Q_WS_WIN
 #include <termios.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -62,12 +65,18 @@
 int MyPtyProcess::init()
 {
     delete m_pPTY;
+#ifndef Q_WS_WIN
     m_pPTY = new KPty();
     if (!m_pPTY->open())
     {
         kError(PTYPROC) << k_lineinfo << "Master setup failed.\n" << endl;
         return -1;
     }
+#else
+    m_pPTY = new KProcess();
+    m_pPTY->setOutputChannelMode(KProcess::MergedChannels);
+#endif
+
     m_stdoutBuf.resize(0);
     m_stderrBuf.resize(0);
     m_ptyBuf.resize(0);
@@ -103,12 +112,39 @@
         } else
         {
             ret = inbuf.left(pos);
+#ifdef Q_WS_WIN
+            if( ret.endsWith('\r') )
+            {
+                ret.chop(1);
+            }
+#endif
             inbuf = inbuf.mid(pos+1);
         }
         return ret;
 
     }
 
+#ifdef Q_WS_WIN
+    if( m_pPTY->waitForReadyRead(60000) )
+    {
+        inbuf = m_pPTY->readAll();
+        pos = inbuf.indexOf('\n');
+        if (pos == -1)
+        {
+            ret = inbuf;
+            inbuf.resize(0);
+        } else
+        {
+            ret = inbuf.left(pos);
+            if( ret.endsWith('\r') )
+            {
+                ret.chop(1);
+            }
+            inbuf = inbuf.mid(pos+1);
+        } 
+    }
+    return ret;
+#else
     int flags = fcntl(fd, F_GETFL);
     if (flags < 0) 
     {
@@ -157,14 +193,23 @@
     }
 
     return ret;
+#endif
 }
 
 void MyPtyProcess::writeLine(QByteArray line, bool addnl)
 {
     if (!line.isEmpty())
+#ifndef Q_WS_WIN    
         write(fd(), line, line.length());
+#else
+        m_pPTY->write(line);
+#endif        
     if (addnl)
+#ifndef Q_WS_WIN
         write(fd(), "\n", 1);
+#else
+        m_pPTY->write("\r\n");
+#endif
 }
 
 void MyPtyProcess::unreadLineFrom(QByteArray inbuf, QByteArray line, bool addnl)
@@ -183,10 +228,18 @@
 int MyPtyProcess::exec(QByteArray command, QCStringList args)
 {
   kDebug(PTYPROC) << "MyPtyProcess::exec(): " << command;// << ", args = " << args ;
-
     if (init() < 0)
         return -1;
-
+#ifdef Q_WS_WIN
+    QStringList ar;
+    for(int i = 0; i < args.size(); ++i)
+    {
+        ar << args[i];
+    }
+    m_pPTY->setProgram(command, ar);
+    m_pPTY->start();
+    return 0;
+#else
     // Open the pty slave before forking. See SetupTTY()
     int slave = open(m_pPTY->ttyName(), O_RDWR);
     if (slave < 0) 
@@ -274,6 +327,7 @@
     kError(PTYPROC) << k_lineinfo << "execv(\"" << path << "\"): " << perror << "\n";
     _exit(1);
     return -1; // Shut up compiler. Never reached.
+#endif
 }
 
 /*
@@ -288,6 +342,7 @@
 
 int MyPtyProcess::WaitSlave()
 {
+#ifndef Q_WS_WIN
     int slave = open(m_pPTY->ttyName(), O_RDWR);
     if (slave < 0) 
     {
@@ -316,13 +371,16 @@
 	break;
     }
     close(slave);
+#endif
     return 0;
 }
 
 
 int MyPtyProcess::enableLocalEcho(bool enable)
 {
+#ifndef Q_WS_WIN
     return m_pPTY->setEcho(enable) ? 0 : -1;
+#endif
 }
 
 
@@ -336,6 +394,7 @@
 
 int MyPtyProcess::waitForChild()
 {
+#ifndef Q_WS_WIN
     int ret, state, retval = 1;
     struct timeval tv;
 
@@ -394,6 +453,7 @@
     }
 
     return -retval;
+#endif
 }
    
 /*
@@ -404,7 +464,8 @@
  */
 
 int MyPtyProcess::setupTTY()
-{    
+{
+#ifndef Q_WS_WIN
     // Reset signal handlers
     for (int sig = 1; sig < NSIG; sig++)
        signal(sig, SIG_DFL);
@@ -432,6 +493,6 @@
         kError(PTYPROC) << k_lineinfo << "tcsetattr(): " << perror << "\n";
         return -1;
     }
-
+#endif
     return 0;
 }
Index: process.h
===================================================================
--- process.h	(revision 883883)
+++ process.h	(working copy)
@@ -12,11 +12,15 @@
 #ifndef __Process_h_Included__
 #define __Process_h_Included__
 
-#include <kpty.h>
-
 #include <QtCore/QByteArray>
 #include <QtCore/QList>
 
+#ifndef Q_WS_WIN
+#include <kpty.h>
+#else
+#include <kprocess.h>
+#endif
+
 #define PTYPROC 7120
 
 typedef QList<QByteArray> QCStringList;
@@ -51,10 +55,18 @@
      * @return The output string.
      */
     QByteArray readLine(bool block = true)
+#ifndef Q_WS_WIN
         { return readLineFrom(fd(), m_ptyBuf, block); }
+#else
+        { return readLineFrom(0, m_ptyBuf, block); }
+#endif
 
     QByteArray readLineFromPty(bool block = true)
+#ifndef Q_WS_WIN
         { return readLineFrom(fd(), m_ptyBuf, block); }
+#else
+        { return readLineFrom(0, m_ptyBuf, block); }
+#endif
 
     QByteArray readLineFromStdout(bool block = true)
         { return readLineFrom(m_stdinout, m_stdoutBuf, block); }
@@ -116,8 +128,11 @@
     void setErase(bool erase) { m_bErase = erase; }
 
     /** Return the filedescriptor of the process. */
+#ifndef Q_WS_WIN
     int fd() {return m_pPTY ? m_pPTY->masterFd() : -1;}
-
+#else
+    KProcess *fd() {return m_pPTY;}
+#endif
     /** Return the pid of the process. */
     int pid() {return m_Pid;}
 
@@ -134,7 +149,11 @@
     int init();
     int setupTTY();
 
+#ifndef Q_WS_WIN
     KPty *m_pPTY;
+#else
+    KProcess *m_pPTY;
+#endif
     QByteArray m_ptyBuf, m_stderrBuf, m_stdoutBuf;
 
     QByteArray readLineFrom(int fd, QByteArray& inbuf, bool block);
