Visit Our UNIX and Linux User Community


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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed to transfer list of files to FTP server, to different folders
# 1  
Old 06-24-2009
Bug 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
# 2  
Old 06-25-2009
Easy in php

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

PHP Code:
#! /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);

?>
# 3  
Old 06-25-2009
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/

Last edited by amazon; 06-25-2009 at 04:57 PM..
# 4  
Old 06-25-2009
many ways to skin that cat - not tested....
assuming fromTo.txt:
Code:
file1 /src/pdf/ /tgt/act1/pdf/
file2 /src/txt/ /tgt/act1/txt/
file3 /src/pdf/ /tgt/act2/pdf/
file4 /src/pdf/ /tgt/act1/pdf/

Code:
#!/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


Last edited by vgersh99; 06-25-2009 at 05:17 PM..
# 5  
Old 06-27-2009
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

Quote:
Originally Posted by vgersh99
many ways to skin that cat - not tested....
assuming fromTo.txt:
Code:
file1 /src/pdf/ /tgt/act1/pdf/
file2 /src/txt/ /tgt/act1/txt/
file3 /src/pdf/ /tgt/act2/pdf/
file4 /src/pdf/ /tgt/act1/pdf/

Code:
#!/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


Last edited by amazon; 06-30-2009 at 10:14 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #915
Difficulty: Easy
In Javascript, 'UNIX.com'.slice(); returns UNIX.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Shell Programming and Scripting

Do I require remote login access to a windows server to transfer files from a UNIX server

Hi All I need to transfer a file from a UNIX server to a windows server. I saw that it is possible to do this using scp command by looking at the forum listed below: ... (2 Replies)
Discussion started by: vx04
2 Replies

3. IP Networking

How to transfer files from UNIX server to windows machine or vice versa using ftp or sftp commands?

hi, i want to write a shell script code which transfers files from a directory in unix server to a directory in a windows machine.. can any1 give me a sample code which uses ftp or sftp command.. thanks very much, (3 Replies)
Discussion started by: Little
3 Replies

4. Shell Programming and Scripting

Transfer files from linux server to windows using secure ftp (sftp)

HI, I have to transfer files from linux server to windows using secure ftp (sftp) .Kindly help me out. (3 Replies)
Discussion started by: manushi88
3 Replies

5. Shell Programming and Scripting

Using SFTP and FTP to transfer data from One Remote Server To Another

HI I need to write a script in 415univ server which should go to 534unix server and move the files from there to windows server. I am not able to get it bcoz sftp prompt is not allowing ftp command. Can some one plz help me Thanks in advance (3 Replies)
Discussion started by: himakiran9
3 Replies

6. Shell Programming and Scripting

RSYNC script to transfer folders recursively without overwriting via FTP

Hi all, I would need a bash script to sync/transfer folders recursively via FTP/RSYNC (I initially planned to use FTP but I heard RSYNC would fit a lot better for this job(?)) The situation: 3 different Linux servers 1. source 2. destination - Samba 3. Server where the script runs on ... (2 Replies)
Discussion started by: thibautp
2 Replies

7. Shell Programming and Scripting

list files on a server ftp

Hello, I would want to list files of an server FTP with the path of the file... i try "ls -R" but ftp don't accept this command... Is it possible with curl command ??? Regards. (5 Replies)
Discussion started by: protocomm
5 Replies

8. Shell Programming and Scripting

Script for FTP (transfer only new files)

Hi everybody, I just want to transfer files with FTP (mget and mput). The problem is that I dont want to overwrite any existing files and don't want to transfer them again (e.g. using the rename-function). So I only want to transfer new files with mget and mput. My first idea was to create... (3 Replies)
Discussion started by: inoxx
3 Replies

9. Filesystems, Disks and Memory

server Hangs during FTP transfer

We are backing up a oracle database by copying the datafiles from one server to another using FTP. while in the middle of the transfer the destination server closes the connection and it sort of hangs. After this we are not able to log onto the destination server using any other user apart from... (0 Replies)
Discussion started by: sgoundar
0 Replies

10. UNIX for Dummies Questions & Answers

Transfer files from Unix server to Windows using FTP

Dear Friend, I don't know much about unix.I am an VB6.0 Programmer.I need to move an text files as aaa.txt from unix server to windows "D: " driver using the FTP protocol.Is it possible to do this with help of unix shell script.If possible please give some sample codes. Please answer as early... (1 Reply)
Discussion started by: gjsaravanan
1 Replies

Featured Tech Videos