current day remote files from FTP

Hi All,

I have to work on a korn shell script to pick up only the current day files dropped on the remote server (using ftp).
The file do not have daytimestamp on it. It has to be based on server time (AIX)

The file naming convention is "test_file.txt"

When I log in into the ftp account from browser I can see the day the file dropped.

However when I log in from the server using ftp commands manually, I can't find the day the file arrived.

Can somoene please help me with the script.

Thanks & Regards
pavan

After issuing a suitable ftp cd command. Please post a small sample from the ftp command dir command. Preferably include a sample where the date is a single digit day.
This should show posters the format on your system.

ftp -inv $ftp_host
$user
$password
cd $ftp_dir
ls test_file.txt
ls_test_file.txt
get test_file.txt
bye

however I don't know from above when the file was dropped on the server. I have to pick up only if the file was dropped today.

Thanks
Pavan

Please reply to my post #2.

You cannot do the entire process with only FTP.
This is going to end up as a multi-stage process:
1) FTP: Get a directory listing from the remote directory
2) Shell: Process the directory listing to find today's files
3) FTP: Get only the file(s) identified above

Btw. The conventional design of this sort of process is to rename the files after successful transfer so it is easy to identify new files.

This is a new process I am trying to put in place. since we pick up files from external remote server, I don't have rename privileges (or the user ID that I am using.) They give us read only previleges.

can you please tell me how do I achieve this,

FTP: Get a directory listing from the remote directory

Thanks
Pavan

1) log in with ftp
2) ls

I ran the following FTP commands manually (on AIX server )

ftp -inv $ftp_host
$user
$password
cd $ftp_dir
ls test_file.txt
ls_test_file.txt
get test_file.txt
bye

when i do ls <filename>

it just list the file but it will not give me complete listing such as

-rwxr-xr-x    1 <user>   <usr>            4746 Apr 11 12:13 test_file.txt

how do I get this complete listing,

Thanks
Pavan

Could you show what it does list when you do ls?

If it doesn't give you a complete listing, you can try ls -l, but remember, ftp is not a shell. You don't get the real ls command. This simple listing might be all you get.

I logged in manually using sftp and I am able to view the file with ls -l

sftp>ls -l
-rwxr-xr-x    1 <userid>   <user id>            4743 Apr 11 11:01 test_file.txt
bye

Can you someone please let me know how do I get the entire file listing from remote server to the local server.

Thanks
Pavan

ftp >outputfile <<EOF
        $user
        $password
        cd $ftp_dir
        ls -l
        bye
EOF

The ending EOF must be at the beginning of the line. Don't even indent it. You can indent the rest as you please.

I ran the following SFTP commands manually (on AIX server )

sftp -p $sftp_user@ftp_host
cd $ftp_dir
ls -l test_file.txt
-rwxr-xr-x 1 <user> <usr> 4746 Apr 11 12:13 test_file.txt
bye

Can someone please tell me how to I get the complete file listing to local server from remote server

-rwxr-xr-x 1 <user> <usr> 4746 Apr 11 12:13 test_file.txt

how do I get this complete listing,

Thanks
Pavan

sftp != ftp

Which do you need to use?

Please do type the ftp dir command requested in post #2. It is not always the same as ls in ftp (but it might be the same) .

To answer your main question:
Within ftp there is a special syntax for the dir command to output the directory listing to a local file. This is useful to us.

These are ftp commands not Shell commands.

Make sure that your current local directory is suitable to receive the directory listing:

lcd suitable_dir

Then list the files in the directory and output to a file on the local server:

dir * mydirectory.lst

Once we have the directory listing we can find today's files. But, because date formats vary across the planet we need to see the date format.

Corona688 makes a valid point. Are you running ftp or sftp ?

I am using sftp since I can't perform ls -l using ftp.

Once you arrange passwordless login for sftp, which is done the same way for scp/sftp/ssh, you can do this:

sftp username@host >filename <<EOF
cd $mypath
ls -l
bye
EOF

Anyway, first time I have seen a server set for both ftp and sftp .

Ignoring the ftp command ls -l which is not always supported (as you have found), please do type the universal (works with every version of ftp ever) command dir .

Off topic. The ftp command dir predates Microsoft. There is a debate in the What's on your mind Forum about whether to call a Directory a Folder. I rest my case.