Index: /trunk/ippScripts/scripts/receive_file.pl
===================================================================
--- /trunk/ippScripts/scripts/receive_file.pl	(revision 23893)
+++ /trunk/ippScripts/scripts/receive_file.pl	(revision 23894)
@@ -65,5 +65,5 @@
 my $filename = "$tempdir/$file";  # Target filename
 {
-    my $uri = "$source/product/$fileset/$file"; # URI for datastore file
+    my $uri = "$source/$product/$fileset/$file"; # URI for datastore file
     my $command = "dsget --uri $uri --filename $filename"; # Command to execute
 
@@ -81,4 +81,5 @@
 
     my $command = "$tool -importrun -infile $filename"; # Command to execute
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
@@ -88,10 +89,11 @@
     my @files = ();
     {
-        my $command = "tar -C $tempdir -tvzf $filename"; # Command to execute
+        my $command = "tar -C $tempdir -tzf $filename"; # Command to execute
         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
             run(command => $command, verbose => $verbose);
         die "Unable to get listing of tar file $filename\n" unless $success;
 
-        foreach my $line (@$stdout_buf) {
+        my @lines = split(/\n/, join "", @$stdout_buf); # Lines from output
+        foreach my $line ( @lines ) {
             $line =~ s/\#.*$//;
             next unless $line =~ /\S+/;
@@ -99,5 +101,5 @@
             my $file = $fields[0];      # Name of file
             $file =~ s|^./||;
-            push @files, $file if defined $file;
+            push @files, $file if $file =~ /\S+/;
         }
     }
@@ -115,5 +117,5 @@
         my $from = "$tempdir/$file"; # Source for file
         my $target = "$workdir/$file"; # Target destination for file
-        my $to = $ipprc->file_prepare( $target ); # Target for move
+        my $to = $ipprc->file_create( $target ); # Target for move
         system("mv $from $to") == 0 or die "Unable to move $file into workdir $workdir: $!\n";
     }
@@ -129,8 +131,11 @@
 {
     my $command = "$receivetool -addresult";
-    $command .= " -file $file_id";
+    $command .= " -file_id $file_id";
     $command .= (" -dtime_copy " . (($mjd_copy - $mjd_start) * 86400));
-    $command .= (" -dtime_extract " . (($mjd_extract - $mjd_start) * 86400));
+    $command .= (" -dtime_extract " . (($mjd_extract - $mjd_copy) * 86400));
     $command .= " -dbname $dbname" if defined $dbname;
+
+
+    print "$command\n";
 
     unless (defined $no_update) {
Index: /trunk/ippScripts/scripts/receive_fileset.pl
===================================================================
--- /trunk/ippScripts/scripts/receive_fileset.pl	(revision 23893)
+++ /trunk/ippScripts/scripts/receive_fileset.pl	(revision 23894)
@@ -55,5 +55,5 @@
 my @files = ();                 # Files to add
 {
-    my $uri = "$source/product/$fileset"; # URI for datastore fileset
+    my $uri = "$source/$product/$fileset"; # URI for datastore fileset
     $uri .= "/index.txt" unless $uri =~ m|/index.txt$|;
     my $command = "dsfilesetls --uri $uri"; # Command to execute
@@ -64,5 +64,6 @@
 
     # Get files
-    foreach my $line (@$stdout_buf) {
+    my @lines = split(/\n/, join "", @$stdout_buf); # Lines from output
+    foreach my $line ( @lines ) {
         $line =~ s/\#.*$//;
         next unless $line =~ /\S+/;
@@ -77,5 +78,5 @@
     my $command = "receivetool -addfile"; # Command to execute
     $command .= " -fileset_id $fileset_id";
-    $command .= " -file" . join(' -file', @files);
+    $command .= " -file " . join(' -file ', @files);
     $command .= " -dbname $dbname" if defined $dbname;
 
Index: /trunk/ippScripts/scripts/receive_source.pl
===================================================================
--- /trunk/ippScripts/scripts/receive_source.pl	(revision 23893)
+++ /trunk/ippScripts/scripts/receive_source.pl	(revision 23894)
@@ -55,5 +55,5 @@
 $uri .= "/index.txt" unless $uri =~ m|/index.txt$|;
 my $command = "dsproductls --uri $uri"; # Command to execute
-$command .= "--last_fileset $last_fileset" if defined $last_fileset;
+$command .= " --last_fileset $last_fileset" if defined $last_fileset;
 
 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -61,7 +61,8 @@
 die "Unable to get source listing from $source for $product\n" unless $success;
 
-# Add filesets
-my $last;                   # Last fileset seen
-foreach my $line (@$stdout_buf) {
+# Parse list of filesets
+my @filesets = ();              # Filesets to add
+my @lines = split(/\n/, join "", @$stdout_buf); # Lines from output
+foreach my $line ( @lines ) {
     $line =~ s/\#.*//g;
     next unless $line =~ /\S+/;
@@ -69,30 +70,35 @@
     my @fields = split(/\s+/, $line); # Fields in line
     my $fileset = $fields[1];
-    next if not defined $fileset;
-
-    my $command = "receivetool -addfileset"; # Command to execute
-    $command .= " -source_id $source_id";
-    $command .= " -fileset $fileset";
-    $command .= " -dbname $dbname" if defined $dbname;
-
-    unless (defined $no_update) {
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbose);
-        die "Unable to add fileset $fileset\n" unless $success;
-        $last = $fileset;
-    }
+    push @filesets, $fileset if defined $fileset and $fileset =~ /\S+/;
 }
 
-# Update the last fileset seen
-if (defined $last and (not defined $last_fileset or $last ne $last_fileset)) {
-    my $command = "receivetool -updatelast"; # Command to execute
-    $command .= " -source_id $source_id";
-    $command .= " -fileset $last";
-    $command .= " -dbname $dbname" if defined $dbname;
+if (scalar @filesets > 0) {
+    # Add filesets
+    {
+        my $command = "receivetool -addfileset"; # Command to execute
+        $command .= " -src_id $source_id";
+        $command .= " -fileset " . join(' -fileset ', @filesets);
+        $command .= " -dbname $dbname" if defined $dbname;
 
-    unless (defined $no_update) {
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbose);
-        die "Unable to update last fileset to $last\n" unless $success;
+        unless (defined $no_update) {
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => $verbose);
+            die "Unable to add filesets from $source for $product\n" unless $success;
+        }
+    }
+
+    # Update the last fileset seen
+    {
+        my $command = "receivetool -updatelast"; # Command to execute
+        $command .= " -src_id $source_id";
+        my $last = pop @filesets; # Last fileset
+        $command .= " -fileset $last";
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        unless (defined $no_update) {
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => $verbose);
+            die "Unable to update last fileset to $last\n" unless $success;
+        }
     }
 }
Index: /trunk/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- /trunk/ippTools/share/pxadmin_drop_tables.sql	(revision 23893)
+++ /trunk/ippTools/share/pxadmin_drop_tables.sql	(revision 23894)
@@ -69,4 +69,8 @@
 DROP TABLE IF EXISTS rcDSFileset;
 DROP TABLE IF EXISTS rcRun;
+DROP TABLE IF EXISTS receiveSource;
+DROP TABLE IF EXISTS receiveFileset;
+DROP TABLE IF EXISTS receiveFile;
+DROP TABLE IF EXISTS receiveResult;
 
 SET FOREIGN_KEY_CHECKS=1
Index: /trunk/ippTools/share/receivetool_pendingfile.sql
===================================================================
--- /trunk/ippTools/share/receivetool_pendingfile.sql	(revision 23893)
+++ /trunk/ippTools/share/receivetool_pendingfile.sql	(revision 23894)
@@ -1,6 +1,13 @@
-SELECT *
+SELECT
+    receiveFile.file_id,
+    source,
+    product,
+    workdir,
+    fileset,
+    file
 FROM receiveFile
 JOIN receiveFileset USING(fileset_id)
 JOIN receiveSource USING(source_id)
-LEFT JOIN receiveResult USING(file_id)
-WHERE receiveFile.file_id IS NULL
+LEFT JOIN receiveResult
+    ON receiveResult.file_id = receiveFile.file_id
+WHERE receiveResult.file_id IS NULL
Index: /trunk/ippTools/src/receivetool.c
===================================================================
--- /trunk/ippTools/src/receivetool.c	(revision 23893)
+++ /trunk/ippTools/src/receivetool.c	(revision 23894)
@@ -95,9 +95,9 @@
 
     // required
-    PXOPT_LOOKUP_STR(source, config->args, "-stage", true, false);
+    PXOPT_LOOKUP_STR(source, config->args, "-source", true, false);
     PXOPT_LOOKUP_STR(product, config->args, "-product",  true, false);
+    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
 
     // optional
-    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
     PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
     PXOPT_LOOKUP_STR(last, config->args, "-last",  false, false);
@@ -168,8 +168,34 @@
 
     // required
-    PXOPT_LOOKUP_S64(source_id, config->args, "-source_id", true, false);
-    PXOPT_LOOKUP_STR(fileset, config->args, "-fileset",  true, false);
-
-    if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset)) {
+    PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
+    psMetadataItem *filesets = psMetadataLookup(config->args, "-fileset");
+    if (!filesets) {
+        psError(PS_ERR_UNKNOWN, true, "-fileset is required");
+        return false;
+    }
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+
+    psListIterator *iter = psListIteratorAlloc(filesets->data.list, PS_LIST_HEAD, false); // Iterator
+    psMetadataItem *item = NULL;        // Item from iteration
+    while ((item = psListGetAndIncrement(iter))) {
+        psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
+
+        if (!receiveFilesetInsert(config->dbh, 0, source_id, item->data.str)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
+            if (!psDBTransaction(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "Database error");
+                return false;
+            }
+            psFree(iter);
+            return false;
+        }
+    }
+    psFree(iter);
+
+    if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
@@ -184,5 +210,5 @@
 
     // required
-    PXOPT_LOOKUP_S64(source_id, config->args, "-source_id", true, false);
+    PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
     PXOPT_LOOKUP_STR(fileset, config->args, "-fileset",  true, false);
 
@@ -212,4 +238,8 @@
     PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
     PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
+
+    // optional
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psString query = pxDataGet("receivetool_pendingfileset.sql");
@@ -227,4 +257,10 @@
     psFree(where);
 
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
     if (!p_psDBRunQueryF(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
@@ -244,5 +280,5 @@
         return true;
     }
-    if (!ippdbPrintMetadatas(stdout, output, "receiveFileset", true)) {
+    if (!ippdbPrintMetadatas(stdout, output, "receiveFileset", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "Failed to print array");
         psFree(output);
@@ -260,7 +296,33 @@
     // required
     PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
-    PXOPT_LOOKUP_STR(file, config->args, "-file",  true, false);
-
-    if (!receiveFileInsert(config->dbh, 0, fileset_id, file)) {
+    psMetadataItem *files = psMetadataLookup(config->args, "-file");
+    if (!files) {
+        psError(PS_ERR_UNKNOWN, true, "-file is required");
+        return false;
+    }
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+
+    psListIterator *iter = psListIteratorAlloc(files->data.list, PS_LIST_HEAD, false); // Iterator
+    psMetadataItem *item = NULL;        // Item from iteration
+    while ((item = psListGetAndIncrement(iter))) {
+        psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
+
+        if (!receiveFileInsert(config->dbh, 0, fileset_id, item->data.str)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to add file");
+            if (!psDBTransaction(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "Database error");
+                return false;
+            }
+            psFree(iter);
+            return false;
+        }
+    }
+    psFree(iter);
+
+    if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
@@ -282,4 +344,8 @@
     PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.file_id", "==");
 
+    // optional
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
     psString query = pxDataGet("receivetool_pendingfile.sql");
     if (!query) {
@@ -296,4 +362,10 @@
     psFree(where);
 
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
     if (!p_psDBRunQueryF(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
@@ -313,5 +385,5 @@
         return true;
     }
-    if (!ippdbPrintMetadatas(stdout, output, "receiveFile", true)) {
+    if (!ippdbPrintMetadatas(stdout, output, "receiveFile", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "Failed to print array");
         psFree(output);
@@ -328,5 +400,5 @@
 
     // required
-    PXOPT_LOOKUP_S64(fileset_id, config->args, "-source_id", true, false);
+    PXOPT_LOOKUP_S64(file_id, config->args, "-file_id", true, false);
 
     // optional
@@ -335,5 +407,5 @@
     PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
 
-    if (!receiveResultInsert(config->dbh, fileset_id, dtime_copy, dtime_extract, fault)) {
+    if (!receiveResultInsert(config->dbh, file_id, dtime_copy, dtime_extract, fault)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
Index: /trunk/ippTools/src/receivetoolConfig.c
===================================================================
--- /trunk/ippTools/src/receivetoolConfig.c	(revision 23893)
+++ /trunk/ippTools/src/receivetoolConfig.c	(revision 23894)
@@ -47,5 +47,5 @@
     psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-source", 0, "define source (required)", NULL);
     psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-product", 0, "define product (required)", NULL);
-    psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-workdir",   0, "define workdir", NULL);
+    psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-workdir",   0, "define workdir (required)", NULL);
     psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
     psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-last", 0, "define last fileset", NULL);
@@ -59,10 +59,10 @@
     // -addfileset
     psMetadata *addfilesetArgs = psMetadataAlloc();
-    psMetadataAddS64(addfilesetArgs, PS_LIST_TAIL, "-source_id", 0, "define source_id (required)", 0);
-    psMetadataAddStr(addfilesetArgs, PS_LIST_TAIL, "-fileset", 0, "define fileset (required)", NULL);
+    psMetadataAddS64(addfilesetArgs, PS_LIST_TAIL, "-src_id", 0, "define source_id (required)", 0);
+    psMetadataAddStr(addfilesetArgs, PS_LIST_TAIL, "-fileset", PS_META_DUPLICATE_OK, "define fileset (multiple OK, required)", NULL);
 
     // -updatelast
     psMetadata *updatelastArgs = psMetadataAlloc();
-    psMetadataAddS64(updatelastArgs, PS_LIST_TAIL, "-source_id", 0, "define source_id (required)", 0);
+    psMetadataAddS64(updatelastArgs, PS_LIST_TAIL, "-src_id", 0, "define source_id (required)", 0);
     psMetadataAddStr(updatelastArgs, PS_LIST_TAIL, "-fileset", 0, "define last fileset (required)", NULL);
 
@@ -72,4 +72,6 @@
     psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-product", 0, "search on product", NULL);
     psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
+    psMetadataAddU64(pendingfilesetArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
+    psMetadataAddBool(pendingfilesetArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
 
     // -addfile
@@ -84,4 +86,6 @@
     psMetadataAddStr(pendingfileArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
     psMetadataAddS64(pendingfileArgs, PS_LIST_TAIL, "-fileset_id", 0, "search on fileset_id", 0);
+    psMetadataAddU64(pendingfileArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
+    psMetadataAddBool(pendingfileArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
 
     // -addresult
