To merge files on FTP site before getting them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To merge files on FTP site before getting them
# 1  
Old 03-15-2017
To merge files on FTP site before getting them

I have a job that connects to FTP site, rename, get, delete a file and then process it. The renaming is done in consideration of this is one file name into which data is being accumulated many times within 24 hour cycle.

This is what happens now:
Code:
 ftp -i $FTPHOST <<-EOF
        ren INPFILE $OUTF
        get $OUTF
        del $OUTF
EOF

We got another accumulator file that needs to be brought over and processed together with the original one. We can bring it in in a similar fashion, then merge locally.

My question is there an alternative, to connect to the site, rename both and somehow merge them there and bring in as one file ready to be processed?
# 2  
Old 03-16-2017
Quote:
Originally Posted by migurus

This is what happens now:
Code:
 ftp -i $FTPHOST <<-EOF
        ren INPFILE $OUTF
        get $OUTF
        del $OUTF
EOF

We got another accumulator file that needs to be brought over and processed together with the original one. We can bring it in in a similar fashion, then merge locally.

My question is there an alternative, to connect to the site, rename both and somehow merge them there and bring in as one file ready to be processed?
Not quite sure why you are renaming a remote file only to delete it afterwards:
Code:
 ftp -i $FTPHOST <<-EOF
        get INPFILE $OUTF
        del INPFILE
EOF

I'm not sure you can merge two files remotely with FTP (others can correct me on this) but if you were to use lftp instead, which is much better for scripting FTP as it allows for recovery after failures, you could investigate its cat command:
Code:
cat INPFILE1 INPFILE2 > $OUTF

which when used interactively will save the files locally. I have not tested within a script, however.

Andrew
# 3  
Old 03-16-2017
Thanks for lftp suggestion, but I don't have control over remote systems.

The rename - get - delete scheme works well when your file is being frequently updated on the remote system and you don't want to get a file with some data half-written in.
# 4  
Old 03-17-2017
Quote:
Originally Posted by migurus
Thanks for lftp suggestion, but I don't have control over remote systems.
lftp is a client program that you would run on the local system.
Quote:
The rename - get - delete scheme works well when your file is being frequently updated on the remote system and you don't want to get a file with some data half-written in.
Okay, that makes sense.

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

FTP problem with site exec command

Hello dear Users, I am for the first time in this forum. I come from Germany. Please excuse my bad englisch. My OS is SCO open Server Release 5. I have a problem whith FTP and the command "site exec" if I use the command "ftp> site chmod 777 /tmp/startkpf.sc 200 CHMOD command successful. ... (8 Replies)
Discussion started by: fla5do
8 Replies

2. Shell Programming and Scripting

Expect - get, then move files within FTP site?

Trying to do the following, and it looks like Expect is probably my best bet. Any help greatly appreciated 1) Log onto ftp site 2) Go to folder 3) GET all files matching basename*.txt 4) MOVE those files to a subfolder on the ftp site. I don't need to move it on MY computer, I want to move... (2 Replies)
Discussion started by: mbourgon
2 Replies

3. UNIX for Dummies Questions & Answers

SCP -r from Secure FTP site

Hi all, My problem is simple. I would like to download the contents of a directory on an ftp site. I can access the site through windows, but there are many files and it would be too tedious to click and download each file. Thus, I am trying to use scp -r... (5 Replies)
Discussion started by: cpabrego
5 Replies

4. Shell Programming and Scripting

Problem in Downloading one day old files from FTP site

HI, I'm downloading one day old files from ftp site. Below is my script ---------------------------- printf "open $HOST \n" > ftp.cmd printf "user $USER $PASSWD\n" >> ftp.cmd printf "bin\n" >> ftp.cmd #printf "cd /Models/\n" >> ftp.cmd printf "prompt\n" >> ftp.cmd printf "for oldfile... (4 Replies)
Discussion started by: shekhar_v4
4 Replies

5. Shell Programming and Scripting

script for download files from ftp site

I'm new to scripting. I'm trying to write a script to download files from ftp site, the following is the script and the message i get after running the script. no files were downloaded :( Thanks advance! script: #!/usr/bin/ksh DAY=`date --date="-1 days" +%y%m%d` ftp -v -n "ftp.address" <<... (5 Replies)
Discussion started by: tiff-matt
5 Replies

6. Shell Programming and Scripting

Pulling a list of files from FTP site in a shell script

Hi, I am writting a shell script which will pull a list files (mentioned in one file 1.txt) from external FTP site (for ex: ftp://abcd.efghijk.com/). The 1.txt is in my local unix directory. I have username and password to connect the external FTP site. Also before I pull the files, I need... (0 Replies)
Discussion started by: spatra
0 Replies

7. Solaris

SITE command of FTP not working

Using FTP on Solaris 5.8, I am not able to use the SITE command. It says Invalid command. I am trying to change the permission of the transmitted files to -rw-rw-rw on the destination machine. Any help would be greatly appreciated. (2 Replies)
Discussion started by: gauravsachan
2 Replies

8. UNIX for Advanced & Expert Users

Polling an FTP site for a file

Hi, I'm after a bit of advice for the best way to collect files from an ftp server via a unix process. The main issue here is the frequency, the job needs to check for files every minute or so between 8am and 8pm and pull them down to the box if there is anything there. Originally the... (6 Replies)
Discussion started by: Peejay
6 Replies

9. UNIX for Dummies Questions & Answers

Site command used in ftp script

Hi everyone, can someone please tell me what can be wrong here? Script: ftp -v -n $FTPSERVER<< EOP >$LOGFILE 2>&1 user $USERID $PASSWD ascii site lrecl=500 site cyl site PRI=600 site SEC=300 lcd $FTPLOCALDIR cd $FTPTARGETDIR put $SOURCEFILE $TARGETFILE quit EOP Output:... (11 Replies)
Discussion started by: swoldering
11 Replies

10. UNIX for Dummies Questions & Answers

ftp protocol and quot site chmod 0

i do have a problem with the transaction of pdf-files from a server to another. there was a guy who told me about this command wich i should build in my ftp.put()-method in java. the command called: about quote site chmod 0 filename.. i think its something about filerights but does someone know... (1 Reply)
Discussion started by: calmacroi
1 Replies
Login or Register to Ask a Question