Help needed to transfer list of files to FTP server, to different folders

Hello Unix Gurus,

Help required from you.

My requirement is something like this

I want to create a concurrenct program in Oracle Applications using shell script to transfer files from Apps Server to destination FTP server.

I have created custom program, where I will extract all the mapping details like file_names, source_path and destination_path directories and storing in a database table.

The shell script should take the file_name and transfer the file from source_path (Apps Server) to destination path (FTP server).

Since the count will be around 5000 for each program run, I think it will not a good idea to open FTP connection for each file transfer.

Appreciate If you can suggest the pseudo code (or) please send me any sample codes

Thanks in advance
Syed

This assumes you want to upload all files in a specific directory, opens a single connection, loops/uploads all files, disconnects.

#! /usr/bin/php
<?php

$path = "/path/to/local/dir";
$username = "username";
$password = "******";
$remoteDir = "/path/on/remote";

$c = ftp_connect('ftp.server.com');
$loginResult = ftp_login($c, $username, $password);
if ($handle = opendir($path)) {
   while (false !== ($file = readdir($handle))) {
      if ($file != '.' && $file != '..') {
         $upload = ftp_put($c, "$remoteDir/$file", "$path/$file", FTP_BINARY);
      }
   }
}

ftp_close($c);

?>

Thank you for your reply and sample code

I just need some more details

My Apps server and FTP server are different servers and i want to use only Unix shell scripting (I do not know anything about php and moreever this script i want to integrate with my custom PL/SQL prog).

In my case, source and destination directories are not always same, thats the reason I am storing these values in database mapping table.

ex:
filename --- src --- target

file1 -- /src/pdf/ --- /tgt/act1/pdf/
file2 -- /src/txt/ --- /tgt/act1/txt/
file3 -- /src/pdf/ --- /tgt/act2/pdf/
file4 -- /src/pdf/ --- /tgt/act1/pdf/

many ways to skin that cat - not tested....
assuming fromTo.txt:

file1 /src/pdf/ /tgt/act1/pdf/
file2 /src/txt/ /tgt/act1/txt/
file3 /src/pdf/ /tgt/act2/pdf/
file4 /src/pdf/ /tgt/act1/pdf/
#!/bin/ksh
hostTo='1.1.1.1'
user='myUser'
pass='myPass'
fromTo='fromTo.txt'

ftp -n -v <<EOF
open ${hostTo}
user ${user} ${pass}
$(awk '{print "put " $2 "/" $1 " " $3}' ${fromTo})
EOF

Thanks for the reply and sample code.

Is there any possibility like using SQL table within FTP session, something like [Please

> open FTP connection
> [SQL session open]for records in (select filename,source,dest from mytable )
> loop
> cd dest
> lcd source
> put filename
> update mytable set some_flag='Y' where file_name=filename
> end loop [close SQL session]
> close FTP session

Actually, I have mappings available in my oracle table and I will use the table data for some other validations and business logic. Will be updating the table record for the file successfully FTP'ed to the dest server