diff -ru libiriver-0.0.7/configure libiriver-0.0.7.fts/configure
--- libiriver-0.0.7/configure	2003-12-09 05:36:35.000000000 +0900
+++ libiriver-0.0.7.fts/configure	2004-05-22 18:21:19.000000000 +0900
@@ -20305,7 +20305,7 @@
 fi
 
 LIBUSB_VERSION=`$LIBUSB_PATH --version`
-if test $LIBUSB_VERSION != "0.1.7"; then
+if test $LIBUSB_VERSION \< "0.1.7"; then
 	{ { echo "$as_me:$LINENO: error: Your libusb is too old : $LIBUSB_VERSION , You need at least
 								0.1.7" >&5
 echo "$as_me: error: Your libusb is too old : $LIBUSB_VERSION , You need at least
diff -ru libiriver-0.0.7/configure.in libiriver-0.0.7.fts/configure.in
--- libiriver-0.0.7/configure.in	2003-12-09 05:33:29.000000000 +0900
+++ libiriver-0.0.7.fts/configure.in	2004-05-22 18:21:19.000000000 +0900
@@ -55,7 +55,7 @@
 fi
 
 LIBUSB_VERSION=`$LIBUSB_PATH --version`
-if test $LIBUSB_VERSION != "0.1.7"; then
+if test $LIBUSB_VERSION \< "0.1.7"; then
 	AC_MSG_ERROR([Your libusb is too old : $LIBUSB_VERSION , You need at least
 								0.1.7])
 fi
diff -ru libiriver-0.0.7/python/Makefile.in libiriver-0.0.7.fts/python/Makefile.in
--- libiriver-0.0.7/python/Makefile.in	2003-12-09 05:36:31.000000000 +0900
+++ libiriver-0.0.7.fts/python/Makefile.in	2004-05-22 18:21:19.000000000 +0900
@@ -162,7 +162,7 @@
 @BUILD_PYTHON_MODULES_TRUE@pythonsiteexecdir = $(pyexecdir)
 @BUILD_PYTHON_MODULES_TRUE@pythonsiteexec_LTLIBRARIES = $(PYTHON_MODULES)
 
-@BUILD_PYTHON_MODULES_TRUE@irivermodule_la_CFLAGS = @PYTHON_INCLUDES@
+@BUILD_PYTHON_MODULES_TRUE@irivermodule_la_CFLAGS = @PYTHON_INCLUDES@ @LIBUSB_CFLAGS@
 @BUILD_PYTHON_MODULES_TRUE@irivermodule_la_SOURCES = pyiriver.c
 @BUILD_PYTHON_MODULES_TRUE@irivermodule_la_LIBADD = $(top_builddir)/src/libiriver.la @LIBS@ @LIBUSB_LIBS@
 @BUILD_PYTHON_MODULES_TRUE@irivermodule_la_LDFLAGS = -module -avoid-version -export-symbols-regex initiriver
diff -ru libiriver-0.0.7/python/pyiriver.c libiriver-0.0.7.fts/python/pyiriver.c
--- libiriver-0.0.7/python/pyiriver.c	2003-12-09 02:58:13.000000000 +0900
+++ libiriver-0.0.7.fts/python/pyiriver.c	2004-05-22 18:21:19.000000000 +0900
@@ -60,12 +60,20 @@
 	    PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
 	    return NULL;
 	} 
-	if (pycompobj == NULL)
-		r = ifp_delete_file(self->d, s, NULL);
-	else {
-		progress_callback = pycompobj;
-		r = ifp_delete_dir(self->d, s, stub_progress_callback);
+	if (pycompobj != NULL) {
+		switch (ifp_file_exists(self->d, s)) {
+		case IRIVER_FILE_EXISTS:
+			r = ifp_delete_file(self->d, s, NULL);
+			break;
+		case IRIVER_DIRECTORY_EXISTS:
+			progress_callback = pycompobj;
+			r = ifp_delete_dir(self->d, s, stub_progress_callback);
+			break;
+		default:
+			break;
+		}
 	}
+
 	if (r == IRIVER_OK) {
 		return Py_BuildValue("b", TRUE);	
 	} else 
diff -ru libiriver-0.0.7/src/iriver.c libiriver-0.0.7.fts/src/iriver.c
--- libiriver-0.0.7/src/iriver.c	2003-12-09 05:24:21.000000000 +0900
+++ libiriver-0.0.7.fts/src/iriver.c	2004-05-22 18:22:03.000000000 +0900
@@ -5,7 +5,7 @@
 #include <unistd.h>
 #include <libgen.h>
 #include "iriver.h"
-#include <ftw.h>
+#include <fts.h>
 
 #define IFP_REQ_TYPE              0xc0
 #define IFP_GET_CAPACITY_REQUEST  0x14
@@ -56,6 +56,7 @@
 #define DEBUG2
 #endif
 
+int comparefts(const FTSENT **a, const FTSENT **b);
 
 static int string2unicode(char *dest, const char *src)
 {
@@ -806,50 +807,47 @@
  **/
 int ifp_upload_dir(usb_dev_handle *dh, const char *id, const char *ld, ifp_progress progress)
 {
-	char *dirname, *iname;
+	FTS *ftsp;
+	FTSENT *ftsentp;
+	size_t basename_pos;
+	int fts_options = FTS_LOGICAL;
 	int r;
-int ftw_process(const char *name, const struct stat *status, int type)
-{
-	if (strcmp(name, ld) == 0) return 0;
-	DEBUG2("ifp_upload_dir(): ftw_process(): begin -- name=%s\n",name);
-	iname = ifp_compose_name(dirname, name + strlen(ld) + 1);
-	if (type == FTW_F)
-	{
-		DEBUG2("ifp_upload_dir(): ftw_process(): ifp_upload_file() -- iname=%s name=%s\n", iname, name);
-		r = ifp_upload_file(dh, iname, name, progress);
-		if ((r == IRIVER_CANNOT_SEND_FILENAME) || (r == IRIVER_GENERIC_USB_ERROR))
-			{
-				DEBUG2("\033[1mifp_upload_dir(): ftw_process(): ifp_upload_file() returns r=%d\033[0m\n",r);
-				sleep(2);
-				if (r == IRIVER_GENERIC_USB_ERROR) // We can safely ignore that. File gets copied. 
-					r = 0;
-				else // This one is a bit more tricky.
-				{
-					DEBUG2("ifp_upload_dir(): ftw_process(): retry ifp_delete_file() and ifp_upload_file()\n");
-					r = ifp_delete_file(dh,iname, progress);
-					DEBUG2("ifp_upload_dir(): ftw_process(): ifp_delete_file() returns r=%d\n",r);
-					ifp_battery_condition(dh);
-					r = ifp_upload_file(dh, iname, name, progress);
-					DEBUG2("ifp_upload_dir(): ftw_process(): ifp_upload_file() returns r=%d\n",r);
-				}
-			}
-		if (r != IRIVER_OK) return r;
-	}
-	if (type == FTW_D)
-	{
-		DEBUG2("ifp_upload_dir(): ftw_process(): ifp_make_dir() - iname=%s\n",iname);
-		if ((r = ifp_make_dir(dh,iname)) != IRIVER_OK) return r;
+	char *argv[2] = {(char*)ld, NULL};
+	char *dirname, *iname;
 
-	}	
-	free(iname);
-	DEBUG2("ifp_upload_dir(): ftw_process(): end\n");
-	return 0;
-}
 	DEBUG("ifp_upload_dir(): begin -- id=%s ld=%s\n",id, ld);
+
+	// XXX why copy to (const char*)id ?
 	if (strcmp(id,"/") == 0) strcpy(id,""); /* FIXME: This is broken */
-	dirname = ifp_compose_name(id, basename(ld));
-	if ((r = ifp_make_dir(dh,dirname)) != IRIVER_OK) return r;
-	ftw(ld, ftw_process, 8);
+
+	if ( (ftsp = fts_open(argv, fts_options, comparefts)) == NULL) {
+	    perror("fts_open");
+	}
+
+	basename_pos = strlen(ld) - strlen(basename(ld));
+
+	while ( (ftsentp = fts_read(ftsp)) != NULL) {
+		iname = ifp_compose_name(id, ftsentp->fts_path + basename_pos);
+
+		switch (ftsentp->fts_info) {
+		case FTS_F:
+			DEBUG2("ifp_upload_dir(): ifp_upload_file() -- iname=%s ftsentp->fts_path=%s\n", iname, ftsentp->fts_path);
+			r = ifp_upload_file(dh, iname, ftsentp->fts_path, progress);
+			break;
+		case FTS_D:
+			DEBUG2("ifp_upload_dir(): ifp_make_dir() - iname=%s\n",iname);
+			r = ifp_make_dir(dh, iname);
+			break;
+		default:
+			break;
+		}
+		free(iname);
+	}
+
+	if (fts_close(ftsp) == -1) {
+		perror("fts_close");
+		return IRIVER_FILE_NOT_FOUND;
+	}
 	DEBUG("ifp_upload_dir(): end -- r=%d\n",r);
 	return r;
 }
@@ -905,8 +903,7 @@
 	for (bus = usb_busses; bus; bus = bus->next)
 		for (tmp_dev = bus->devices; tmp_dev; tmp_dev = tmp_dev->next)
 			if ((tmp_dev->descriptor.idVendor == iRiver_Vendor) && 
-				(tmp_dev->descriptor.idProduct == iFP_Product_1XX ||
-				tmp_dev->descriptor.idProduct == iFP_Product_3XX))
+				((tmp_dev->descriptor.idProduct & 0xFF00) != 0x1100) )
 				dev = tmp_dev;
 	return(dev);
 }
@@ -1021,3 +1018,20 @@
 	}
 	*first = NULL;
 }
+
+int comparefts(const FTSENT **a, const FTSENT **b) {
+    if ( (*a)->fts_info == FTS_ERR || (*b)->fts_info == FTS_ERR) {
+	return 0;
+    }
+    if ( (*a)->fts_info == FTS_NS || (*b)->fts_info == FTS_NS) {
+	if ( (*a)->fts_info != FTS_NS) {
+	    return -1;
+	} else if ( (*b)->fts_info != FTS_NS) {
+	    return 1;
+	} else {
+	    return strcmp( (*a)->fts_name, (*b)->fts_name);
+	}
+    }
+    return strcmp( (*a)->fts_name, (*b)->fts_name);
+}
+
diff -ru libiriver-0.0.7/test/ifp.c libiriver-0.0.7.fts/test/ifp.c
--- libiriver-0.0.7/test/ifp.c	2003-12-09 05:30:17.000000000 +0900
+++ libiriver-0.0.7.fts/test/ifp.c	2004-05-22 18:21:19.000000000 +0900
@@ -137,7 +137,7 @@
 				check_for_error(ifp_download_dir(dh, argv[2], argv[3], progress_func));
 				break;
 			case 14:
-//	check_for_error(ifp_upload_dir(dh, argv[2], argv[3]));
+				check_for_error(ifp_upload_dir(dh, argv[2], argv[3], progress_func));
 				break;
 			case FNC_NUM:
 				help(argv[0]);
