Page 1 of 1

Read Name of a file in remote server SFTP

Posted: Mon Nov 12, 2012 5:36 pm
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

Re: Read Name of a file in remote server SFTP

Posted: Mon Nov 12, 2012 6:21 pm
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.

Re: Read Name of a file in remote server SFTP

Posted: Tue Nov 13, 2012 10:04 am
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. ??

Posted: Tue Nov 13, 2012 10:10 am
by chulett
Sure, using redirection via the ">" or ">>" operators.

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

Re: Read Name of a file in remote server SFTP

Posted: Tue Nov 13, 2012 12:48 pm
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