--- src/CompatMode.cc
+++ src/CompatMode.cc
@@ -0,0 +1,238 @@
+/*
+ * compat mode for lftp
+ *
+ * Copyright (c) 2005 by Petr Ostadal (postadal@suse.cz)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <assert.h>
+#include <pwd.h>
+#include "MirrorJob.h"
+#include "CmdExec.h"
+#include "rmJob.h"
+#include "mkdirJob.h"
+#include "ChmodJob.h"
+#include "misc.h"
+#include "plural.h"
+#include "getopt.h"
+#include "FindJob.h"
+#include "url.h"
+#include "CopyJob.h"
+#include "pgetJob.h"
+
+#include "modconfig.h"
+
+#include <fcntl.h>
+#include <termios.h>
+
+#include "xmalloc.h"
+#include "GetPass.h"
+#include "CharReader.h"
+#include "SignalHook.h"
+#include "Job.h"
+
+
+int ascii_mode;
+
+char* GetText(const char *prompt) {
+   static char *oldtext=0;
+   static int tty_fd=-2;
+   static FILE *f=0;
+
+   xfree(oldtext);
+   oldtext=0;
+
+   if(tty_fd==-2)
+   {
+      if(isatty(0))
+	 tty_fd=0;
+      else
+      {
+	 tty_fd=open("/dev/tty",O_RDONLY);
+   	 if(tty_fd!=-1)
+	    fcntl(tty_fd,F_SETFD,FD_CLOEXEC);
+      }
+   }
+   if(tty_fd==-1)
+      return 0;
+
+   if(f==0)
+      f=fdopen(tty_fd,"r");
+   if(f==0)
+      return 0;
+
+   write(tty_fd,prompt,strlen(prompt));
+   oldtext=readline_from_file(fileno(f));
+   return oldtext;
+}
+
+CMD(ascii)
+{
+    ascii_mode = 1;
+    return NULL;
+}
+
+CMD(bin)
+{
+    ascii_mode = 0;
+    return NULL;
+}
+
+CMD(type) 
+{
+    if (parent->args->count() == 2) {
+        if (strcmp(parent->args->getarg(1), "binary") == 0)
+            ascii_mode = 0;
+        else if (strcmp(parent->args->getarg(1), "ascii") == 0)
+            ascii_mode = 1;
+        else
+            parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+    } else if (parent->args->count() == 1) {
+        if (ascii_mode)
+            parent->printf("Using ascii mode to transfer files.\n");
+        else
+            parent->printf("Using binary mode to transfer files.\n");
+    }
+    else
+        parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+    return NULL;
+}
+
+CMD(user);
+
+CMD(compat_user)
+{
+    char *user;
+
+    if(parent->args->count() == 1) {
+        user = GetText("(username) ");
+        
+        if (!user || strlen(user) == 0) {
+            parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+            return NULL;
+        }
+        user = strdup(user);
+        parent->args->Add(user);
+    }
+    
+    return cmd_user(parent);
+}
+
+CMD(compat_open)
+{
+    const char *myname = getlogin();
+    struct passwd *pw;
+    char *name = NULL;
+    char *prompt = NULL;
+    char *cmd;
+    int len = 0;
+    ascii_mode = 1;
+    Job *job;
+    int n;
+    
+    if (parent->args->count() == 3)
+        parent->args->insarg(2, "-p");
+    else if (parent->args->count() != 2) {
+        parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+        return NULL;
+    }
+    
+    if (myname == NULL && (pw = getpwuid(getuid())) != NULL)
+        myname = pw->pw_name;
+    if (myname) {
+        len = strlen(myname) + 10;
+        prompt = (char*)malloc(len);
+        if (len <= snprintf(prompt, len, "Name (%s): ", myname))
+            prompt[len - 1] = '\0';
+        name = GetText(prompt);
+        name = strdup(name && strlen(name) > 0 ? name : myname);
+        free(prompt);
+    }
+    else {
+        name = GetText("Name: ");
+        if (name) strdup (name);
+    }
+    
+            
+    if (name != NULL && strlen(name) == 0) {
+        free(name);
+        name = NULL;
+    }
+
+    if (name) {
+        len = strlen(name) + 11;
+        cmd = (char*)malloc(len);
+
+        if (len <= snprintf(cmd, len, "lftp-user %s", name))
+            cmd[len - 1] = '\0';
+
+        parent->PrependCmd(cmd);
+
+        free(name);
+        free(cmd);
+    }
+    job = parent->builtin_open();
+    n = job->Do();
+    
+    return job;
+}
+
+CMD(get);
+
+CMD(compat_get)
+{
+    if (ascii_mode && parent->args->count() > 1)
+        parent->args->insarg(1, "-a");
+    
+    return cmd_get(parent);
+}
+
+CMD(get1);
+
+CMD(compat_get1)
+{
+    if (ascii_mode && parent->args->count() > 1)
+        parent->args->insarg(1, "-a");
+    
+    return cmd_get1(parent);
+}
+
+void module_init()
+{
+    ascii_mode = 0;
+
+    CmdExec::RegisterCompatCommand("user", cmd_compat_user, "user <username> [<pass>]", "send new user information (only for backward compatibility, use lftp-user instead)\n");
+    CmdExec::RegisterCompatCommand("open", cmd_compat_open, "open <site> [<port]", "connect to remote ftp server (only for backward compatibility, use lftp-open instead)\n");
+    
+    CmdExec::RegisterCompatCommand("get", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("mget", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("put", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("mput", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("get1", cmd_compat_get1);
+    
+    
+    CmdExec::RegisterCommand("ascii", cmd_ascii, "ascii", "set ascii transfer type\n");
+    CmdExec::RegisterCommand("binary", cmd_bin, "binary", "set binary transfer type\n");
+    CmdExec::RegisterCommand("type", cmd_type, "type [ascii|binary]", "set file transfer type\n");
+}
--- src/CompatMode.h
+++ src/CompatMode.h
@@ -0,0 +1,28 @@
+/*
+ * lftp and utils
+ *
+ * Copyright (c) 2005 by Petr Ostadal (postadal@suse.cz)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef COMPATMODE_H
+#define COMPATMODE_H
+
+#include "Job.h"
+extern int ascii_mode;
+
+
+#endif //COMPATMODE_H
--- src/Makefile.am
+++ src/Makefile.am
@@ -20,7 +20,7 @@
 example_module1_la_LDFLAGS  = -module -avoid-version -rpath $(pkgverlibdir)
 
 TASK_MODULES = liblftp-pty.la liblftp-network.la proto-ftp.la proto-http.la proto-file.la proto-fish.la proto-sftp.la
-JOB_MODULES = liblftp-getdate.la cmd-mirror.la cmd-sleep.la
+JOB_MODULES = liblftp-getdate.la cmd-mirror.la cmd-sleep.la compat-mode.la
 if WITH_MODULES
   pkgverlib_LTLIBRARIES = $(TASK_MODULES) $(JOB_MODULES)
 else
@@ -41,6 +41,7 @@
 liblftp_network_la_SOURCES = NetAccess.cc NetAccess.h Resolver.cc Resolver.h\
  lftp_ssl.cc lftp_ssl.h buffer_ssl.cc buffer_ssl.h
 liblftp_getdate_la_SOURCES = getdate.y getdate.h
+compat_mode_la_SOURCES = CompatMode.cc CompatMode.h
 
 proto_ftp_la_LDFLAGS  = -module -avoid-version -rpath $(pkgverlibdir)
 proto_http_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
@@ -54,6 +55,8 @@
 liblftp_network_la_LIBADD  = $(SOCKSLIBS) $(OPENSSL_LIBS) $(LIBGNUTLS_LIBS)
 liblftp_getdate_la_LDFLAGS = -avoid-version -rpath $(pkgverlibdir)
 
+compat_mode_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
+
 proto_ftp_la_LIBADD  = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la
 proto_http_la_LIBADD = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la $(EXPAT_LIBS)
 proto_fish_la_LIBADD = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la liblftp-pty.la
--- src/lftp_wrapper.c
+++ src/lftp_wrapper.c
@@ -507,17 +507,6 @@
 	    char *buf_url = NULL;
 	    int is = haveFile(buf2);
 
-/**	    if (ftp_port == NULL)
-		snprintf(open, 100,
-			 (anonymous
-			  || isWithUsername(buf2) ? LFTP_OPEN :
-			  LFTP_COMPAT_MODE_OPEN));
-	    else
-		snprintf(open, 100, "%s -p %s",
-			 (anonymous
-			  || isWithUsername(buf2) ? LFTP_OPEN :
-			  LFTP_COMPAT_MODE_OPEN), ftp_port);**/
-
 	    int ishtml,isftp,isfile,ishost,isuser; //flags for url
 	    int tmp_port;
 	    ishtml=isHTML(buf2);
@@ -569,8 +558,7 @@
 			buf_url = get_url(buf2);
 			tmp_port= isPortInUrl(buf2);/* no need to test error message, it is done in get_url() */
 			if(tmp_port)ftp_port_i=tmp_port;
-			snprintf(open, 100,(anonymous || isuser || (isftp && !ishost) ? LFTP_OPEN :
-			  LFTP_COMPAT_MODE_OPEN)); 
+			snprintf(open, 100,LFTP_OPEN); 
 			snprintf(buf, BUFSIZE, "%s %s:%d; %s %s",
 					 open, buf_url, ftp_port_i, get,
 					 buf_file);
@@ -591,9 +579,6 @@
 		    }
 		}
 		
-		/*if (!strncmp
-		    (buf2, ANONYMOUS_PREFIX, strlen(ANONYMOUS_PREFIX)))
-		    anonymous_offset = strlen(ANONYMOUS_PREFIX);*/
 		snprintf(open, 100,(anonymous || isuser) ? LFTP_OPEN :
 			  LFTP_COMPAT_MODE_OPEN);     
 		buf_file = get_file(buf2); /* directory */ 
--- src/Makefile.in.orig	2007-10-06 19:20:49.000000000 +0200
+++ src/Makefile.in	2007-10-06 19:28:13.000000000 +0200
@@ -93,6 +93,11 @@
 am_cmd_sleep_la_OBJECTS = SleepJob.lo
 cmd_sleep_la_OBJECTS = $(am_cmd_sleep_la_OBJECTS)
 @WITH_MODULES_TRUE@am_cmd_sleep_la_rpath = -rpath $(pkgverlibdir)
+compat_mode_la_LIBADD = 
+compat_mode_la_DEPENDENCIES = 
+am_compat_mode_la_OBJECTS = CompatMode.lo
+compat_mode_la_OBJECTS = $(am_compat_mode_la_OBJECTS)
+@WITH_MODULES_TRUE@am_compat_mode_la_rpath = -rpath $(pkgverlibdir)
 example_module1_la_LIBADD =
 am_example_module1_la_OBJECTS = example-module1.lo
 example_module1_la_OBJECTS = $(am_example_module1_la_OBJECTS)
@@ -101,7 +106,7 @@
 liblftp_getdate_la_OBJECTS = $(am_liblftp_getdate_la_OBJECTS)
 @WITH_MODULES_TRUE@am_liblftp_getdate_la_rpath = -rpath \
 @WITH_MODULES_TRUE@	$(pkgverlibdir)
-am__DEPENDENCIES_1 = liblftp-getdate.la cmd-mirror.la cmd-sleep.la
+am__DEPENDENCIES_1 = liblftp-getdate.la cmd-mirror.la cmd-sleep.la compat-mode.la
 @WITH_MODULES_FALSE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
 liblftp_jobs_la_DEPENDENCIES = $(am__DEPENDENCIES_2) liblftp-tasks.la
 am_liblftp_jobs_la_OBJECTS = Job.lo CmdExec.lo commands.lo mgetJob.lo \
@@ -198,7 +203,7 @@
 YACCCOMPILE = $(YACC) $(YFLAGS) $(AM_YFLAGS)
 LTYACCCOMPILE = $(LIBTOOL) --mode=compile $(YACC) $(YFLAGS) \
 	$(AM_YFLAGS)
-SOURCES = $(cmd_mirror_la_SOURCES) $(cmd_sleep_la_SOURCES) \
+SOURCES = $(cmd_mirror_la_SOURCES) $(cmd_sleep_la_SOURCES) $(compat_mode_la_SOURCES) \
 	$(example_module1_la_SOURCES) $(liblftp_getdate_la_SOURCES) \
 	$(liblftp_jobs_la_SOURCES) $(liblftp_network_la_SOURCES) \
 	$(liblftp_pty_la_SOURCES) $(liblftp_tasks_la_SOURCES) \
@@ -206,7 +211,7 @@
 	$(proto_ftp_la_SOURCES) $(proto_http_la_SOURCES) \
 	$(proto_sftp_la_SOURCES) $(example1_SOURCES) \
 	$(example1_cmd_SOURCES) $(example2_SOURCES) $(lftp_SOURCES)
-DIST_SOURCES = $(cmd_mirror_la_SOURCES) $(cmd_sleep_la_SOURCES) \
+DIST_SOURCES = $(cmd_mirror_la_SOURCES) $(cmd_sleep_la_SOURCES) $(compat_mode_la_sources) \
 	$(example_module1_la_SOURCES) $(liblftp_getdate_la_SOURCES) \
 	$(liblftp_jobs_la_SOURCES) $(liblftp_network_la_SOURCES) \
 	$(liblftp_pty_la_SOURCES) $(liblftp_tasks_la_SOURCES) \
@@ -366,7 +371,7 @@
 example_module1_la_SOURCES = example-module1.cc
 example_module1_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
 TASK_MODULES = liblftp-pty.la liblftp-network.la proto-ftp.la proto-http.la proto-file.la proto-fish.la proto-sftp.la
-JOB_MODULES = liblftp-getdate.la cmd-mirror.la cmd-sleep.la
+JOB_MODULES = liblftp-getdate.la cmd-mirror.la cmd-sleep.la compat-mode.la
 @WITH_MODULES_TRUE@pkgverlib_LTLIBRARIES = $(TASK_MODULES) $(JOB_MODULES)
 @WITH_MODULES_FALSE@TASK_MODULES_STATIC = $(TASK_MODULES)
 @WITH_MODULES_FALSE@JOB_MODULES_STATIC = $(JOB_MODULES)
@@ -380,6 +385,7 @@
 proto_sftp_la_SOURCES = SFtp.cc SFtp.h
 cmd_mirror_la_SOURCES = MirrorJob.cc MirrorJob.h
 cmd_sleep_la_SOURCES = SleepJob.cc SleepJob.h
+compat_mode_la_SOURCES = CompatMode.cc CompatMode.h
 liblftp_pty_la_SOURCES = PtyShell.cc PtyShell.h lftp_pty.c lftp_pty.h
 liblftp_network_la_SOURCES = NetAccess.cc NetAccess.h Resolver.cc Resolver.h\
  lftp_ssl.cc lftp_ssl.h buffer_ssl.cc buffer_ssl.h
@@ -392,6 +398,7 @@
 proto_sftp_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
 cmd_mirror_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
 cmd_sleep_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
+compat_mode_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
 liblftp_pty_la_LDFLAGS = -avoid-version -rpath $(pkgverlibdir)
 liblftp_network_la_LDFLAGS = -avoid-version -rpath $(pkgverlibdir) $(OPENSSL_LDFLAGS)
 liblftp_network_la_LIBADD = $(SOCKSLIBS) $(OPENSSL_LIBS) $(LIBGNUTLS_LIBS)
@@ -402,6 +409,7 @@
 proto_sftp_la_LIBADD = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la liblftp-pty.la
 cmd_mirror_la_LIBADD = liblftp-getdate.la
 cmd_sleep_la_LIBADD = liblftp-getdate.la
+compat_mode_la_LIBADD = 
 liblftp_tasks_la_SOURCES = PollVec.cc PollVec.h SMTask.cc SMTask.h ProcWait.cc\
  ProcWait.h GetPass.cc GetPass.h ConnectionSlot.cc ConnectionSlot.h\
  CharReader.cc CharReader.h Cache.cc Cache.h LsCache.cc LsCache.h\
@@ -540,6 +548,8 @@
 	$(CXXLINK) $(am_cmd_mirror_la_rpath) $(cmd_mirror_la_LDFLAGS) $(cmd_mirror_la_OBJECTS) $(cmd_mirror_la_LIBADD) $(LIBS)
 cmd-sleep.la: $(cmd_sleep_la_OBJECTS) $(cmd_sleep_la_DEPENDENCIES) 
 	$(CXXLINK) $(am_cmd_sleep_la_rpath) $(cmd_sleep_la_LDFLAGS) $(cmd_sleep_la_OBJECTS) $(cmd_sleep_la_LIBADD) $(LIBS)
+compat-mode.la: $(compat_mode_la_OBJECTS) $(compat_mode_la_DEPENDENCIES) 
+	$(CXXLINK) $(am_compat_mode_la_rpath) $(compat_mode_la_LDFLAGS) $(compat_mode_la_OBJECTS) $(compat_mode_la_LIBADD) $(LIBS)
 example-module1.la: $(example_module1_la_OBJECTS) $(example_module1_la_DEPENDENCIES) 
 	$(CXXLINK)  $(example_module1_la_LDFLAGS) $(example_module1_la_OBJECTS) $(example_module1_la_LIBADD) $(LIBS)
 liblftp-getdate.la: $(liblftp_getdate_la_OBJECTS) $(liblftp_getdate_la_DEPENDENCIES) 
--- src/CmdExec.h.orig	2007-11-02 09:30:37.000000000 +0100
+++ src/CmdExec.h	2007-11-02 09:31:02.000000000 +0100
@@ -219,6 +219,9 @@
    static void RegisterCommand(const char *name,cmd_creator_t creator,
       const char *short_name=0,const char *long_name=0);
 
+   static void RegisterCompatCommand(const char *name,cmd_creator_t creator,
+      const char *short_name=0,const char *long_name=0);
+
    Job *builtin_lcd();
    Job *builtin_cd();
    Job *builtin_open();
--- src/CmdExec.cc.orig	2007-11-02 09:17:02.000000000 +0100
+++ src/CmdExec.cc	2007-11-02 09:30:10.000000000 +0100
@@ -1165,6 +1165,38 @@
    dyn_cmd_table.append(new_entry);
 }
 
+void CmdExec::RegisterCompatCommand(const char *name,cmd_creator_t creator,const char *short_desc,const char *long_desc)
+{
+   if(dyn_cmd_table==0)
+   {
+      int count=0;
+      for(const cmd_rec *c=static_cmd_table; c->name; c++)
+        count++;
+      dyn_cmd_table.nset(static_cmd_table,count);
+   }
+   for(int i=0; i<dyn_cmd_table.count(); i++)
+   {
+      cmd_rec *const c=&dyn_cmd_table[i];
+      if(!strcmp(c->name,name))
+      {
+          char *lftp_name=(char*)malloc(5+strlen(name)+1);
+          char *short_d = NULL;
+
+          if (c->short_desc) {
+              short_d = (char*)malloc(5+strlen(c->short_desc)+1);
+              sprintf(short_d, "lftp-%s", c->short_desc);
+              c->short_desc = short_d;
+          }
+
+          sprintf(lftp_name, "lftp-%s", name);
+          c->name = lftp_name;
+			 return;
+		}
+	}
+   cmd_rec new_entry={name,creator,short_desc,long_desc};
+   dyn_cmd_table.append(new_entry);
+}
+
 void CmdExec::ChangeSession(FileAccess *new_session)
 {
    session=new_session;
