diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index 401484d..e5c5aec 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -24,6 +24,7 @@
 #include <config.h>
 
 #include <stdlib.h>
+#include <sys/poll.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -852,6 +853,9 @@ handle_login (GVfsBackend *backend,
   const gchar *authtype = NULL;
   gchar *object = NULL;
   char *prompt;
+  /*
+   * TODO: compare this with sshfs.c where the prompt appears on stdin_fd
+   */
   
   if (op_backend->client_vendor == SFTP_VENDOR_SSH) 
     prompt_fd = stderr_fd;
@@ -864,14 +868,13 @@ handle_login (GVfsBackend *backend,
   ret_val = TRUE;
   while (1)
     {
-      FD_ZERO (&ifds);
-      FD_SET (stdout_fd, &ifds);
-      FD_SET (prompt_fd, &ifds);
-      
-      tv.tv_sec = SFTP_READ_TIMEOUT;
-      tv.tv_usec = 0;
+      struct pollfd fds[2];
+      fds[0].fd = stdout_fd;
+      fds[0].events = POLLIN;
+      fds[1].fd = prompt_fd;
+      fds[1].events = POLLIN;
       
-      ret = select (MAX (stdout_fd, prompt_fd)+1, &ifds, NULL, NULL, &tv);
+      ret = poll(fds, 2, SFTP_READ_TIMEOUT);
       
       if (ret <= 0)
         {
@@ -882,11 +885,11 @@ handle_login (GVfsBackend *backend,
           break;
         }
       
-      if (FD_ISSET (stdout_fd, &ifds))
+      if (fds[0].revents)
         break; /* Got reply to initial INIT request */
       
-      g_assert (FD_ISSET (prompt_fd, &ifds));
-      
+      if (!(fds[1].revents & POLLIN))
+        continue;
       
       len = g_input_stream_read (prompt_stream,
                                  buffer, sizeof (buffer) - 1,
