1748121 Members
3285 Online
108758 Solutions
New Discussion юеВ

Urgent- Problem in FTP

 
hpuserhk
Frequent Advisor

Urgent- Problem in FTP

Hello Folks,

I need some help urgently , i written script (HP-UX) for ftp files from remote machine,its working fine, but requirement is i have to ftp files from remote machine only of yesterday,filename do not have any string of date , so timestamp is only criteria ,please advice how to ftp files of yesterday

Thanks & Regards
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: Urgent- Problem in FTP

Shalom,

ftp -in myhost << EOF
user username password
get /tmp/bla
get /tmp/foo
EOF

That's how to do it.

That being said, this is very insecure, with the password in the script and being transmitted in clear text along with the data without any encryption.

If you use openssh scp function with password free access, the whole thing can be secure and a less complex script.

Here is how.
http://www.hpux.ws/?p=10

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: Urgent- Problem in FTP

>but requirement is i have to ftp files from remote machine only of yesterday, filename do not have any string of date, so timestamp is only criteria

This means you will need to first use the "ls" command. Then parse the output, then redo the ftp to copy selected files.
hpuserhk
Frequent Advisor

Re: Urgent- Problem in FTP

Thanks Dennis for prompt reply

But can you eloborate how i do

Do You mean first i ftp all files(are in large number) to local machine,then i use
ls command to filter the files and delete unwanted from local directory

Or you mean some other solution

Is there any way to pass information to ftp session to ftp only files of yesterday timestamp

Thanks
Deepak Kr
Respected Contributor

Re: Urgent- Problem in FTP

using
find / -name "filename*.txt" -mtime 0

shows yesterdays file

using ls -l | awk '{ if ($6 == "Aug" && $7 == "14") ptint $NF,$6,$7 }' > /tmp/filelist.out

Then you can use this file to ftp files

"There is always some scope for improvement"
hpuserhk
Frequent Advisor

Re: Urgent- Problem in FTP

Thanks Deepak

But i need to automate this process,
I mean shell script will run daily as scheduled, ftp files and futher program process this files,so first part is to ftp yesterday files daily from remote machine
James R. Ferguson
Acclaimed Contributor

Re: Urgent- Problem in FTP

Hi:

> But i need to automate this process,
I mean shell script will run daily as scheduled, ftp files and futher program process this files,so first part is to ftp yesterday files daily from remote machine

As Dennis said, you need to connect to your remote server in an FTP session and issue the 'dir' command within FTP. You collect this information in a file in your script.

When this FTP connection is complete, you parse what you need from the file; build any variables necessary; start another FTP session and put or get files as desired.

All of this can be built into one script.

To collect a remote server's file information you do something like:

{ echo "open somehostname
user someuser thepassword
cd remotedir
lcd tempdir
dir remotedir localfile
quit"
} | ftp -i -n -v

...the contents of the "remotedir" on "somehostname" will be written with timestamp information into your "localfile". Parse that and continue processing.

Regards!

...JRF...
hpuserhk
Frequent Advisor

Re: Urgent- Problem in FTP

Thanks JRF

I was trying to get if any way to pass information to ftp about date of file

But if that is not possible i think this alternative solution to dir all files from remote machine and parse list locally then ftp again is ok,but when i dir all files of remote machine to file of local machine then in that list file name and date appears on seperate lines, so its difficult to grep etc
example filename1 01-01-2007
filename 2
09-01-2007

pl suggest how to parse this info

Best Regards
Dennis Handly
Acclaimed Contributor

Re: Urgent- Problem in FTP

>but when i dir all files of remote machine to file of local machine then in that list file name and date appears on separate lines, so it's difficult to grep etc
example filename1 01-01-2007
filename2
09-01-2007

What type of machine is the remote one?
If HP-UX, both ls and dir produce the standard ll(1) output.

To merge the two lines you can use sed:
sed -e 'N; s/\n/ /' file

>JRF: dir remotedir localfile

When I did this interactively, I had to use "prompt" to turn off this question:
output to local-file: localfile? y
James R. Ferguson
Acclaimed Contributor

Re: Urgent- Problem in FTP

Hi (again):

> Dennis: When I did this [dir remotedir localfile] interactively, I had to use "prompt" to turn off this question:
output to local-file: localfile? y

Yes, that appears to be the interactive behavior. If you use the shell snippet I posted, there is no prompt, though.

As for the OP's response that the names and date information (sometimes?) appear on separate lines:

filename1 01-01-2007
filename 2
09-01-2007

...This looks like a Window's listing. Are there evil spaces in filenames? [the dumbest thing Windows ever allowed!!!]

Are the filenames simply long names that wrap around a terminal's display?

It would be helpful if in addition to answering the above, you *posted* (as an *attachement*) the actual directory listing returned by the FTP snippet I suggested. I wonder if there are whitespace and/or other non-printing characters in some of you filenames.

Regards!

...JRF...