Read Name of a file in remote server SFTP

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
akonda
Participant
Posts: 97
Joined: Wed Feb 28, 2007 6:15 am

Read Name of a file in remote server SFTP

Post by akonda »

Guys

I have a datastage job to read a file(sales_20121112_0910.txt) from sftp remote server. I am using path/sales* in ftp stage(parallel job) and able to read data. But I need get exact file name to load into a table. also I need to move the same file to another folder in remote sever.

since I am not able to get the exact name of the file obviously not able to perform rename/move commands.

please advice.

Thanks
satishmailbox
Participant
Posts: 3
Joined: Thu May 17, 2007 4:47 pm

Re: Read Name of a file in remote server SFTP

Post by satishmailbox »

Use External Source stage and run any unix command you want.
Source Method: Specific Program
Source program: ls path/sales*

add a column and it will contain list of filenames.

can use after job sub-routine to move files after processing.
akonda
Participant
Posts: 97
Joined: Wed Feb 28, 2007 6:15 am

Re: Read Name of a file in remote server SFTP

Post by akonda »

I m not able to write multiple unix command in External stage. But
when I give sftp userid@remote.server is working.

Is it possbile to write ls -ltr result into an output. ??
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure, using redirection via the ">" or ">>" operators.

http://en.wikipedia.org/wiki/Redirection_%28Unix%29
-craig

"You can never have too many knives" -- Logan Nine Fingers
bfennell
Participant
Posts: 6
Joined: Fri Nov 09, 2012 12:32 pm

Re: Read Name of a file in remote server SFTP

Post by bfennell »

I am not sure of the issue: do you want to get the file name before you get the file, or after? Do you have access to the remote server via some way other than sftp? If you can get the file with a wildcard, but cannot list the results, you could try putting it in a local directory you know is empty (make a temporary directory for example and put it there) then list the files in that local directory - the only one should be your file. If you want to list the files before you get them, you could try using "ssh hostname ls path/sales*" you may introduce a race condition then. A previous post has already suggested putting the results in a text file for reading.

Brian Fennell
Post Reply