Page 1 of 2

Sftp ing the files and deleting files on remote server.

Posted: Mon Nov 22, 2010 10:00 am
by kollurianu
Hi all ,

After SFTP'ing the source files successfully to the local server , how to delete files from the remote server ? Any inputs greatly appreciated.

Thanks in advance.

Posted: Mon Nov 22, 2010 10:34 am
by ArndW
SFTP allows shelling out on the local host and executing commands. Thus, if your sftp is "push" then it will work, if you "pull" the files then you will need to do something else, perhaps "rsh" or "ssh" to execute the delete command.

Posted: Mon Nov 22, 2010 10:41 am
by narasimha
Another way of doing this is to run sftp -b (Batch mode)
In the batch file you can write a get/mget followed by a rm

Posted: Mon Nov 22, 2010 10:49 am
by kollurianu
ArndW wrote:SFTP allows shelling out on the local host and executing commands. Thus, if your sftp is "push" then it will work, if you "pull" the files then you will need to do something else, perhaps "rsh" or "ssh" to execute the delete command.
Thanks for your response Arnd , I am getting files from remote server to the local datastage server to process them , so how do I do rsh or ssh in the FTP enterprise stage , as I see an open command option but that is used before data transfer .. I need delete files on the remote server after successful tranmission.

Could please elaborate..?Any inputs greatly appreciated.

Thanks in advance.

Posted: Mon Nov 22, 2010 11:04 am
by kollurianu
I am doing SFTP in FTP enterprise stage , so is there a way to perform rsh or ssh to delete the file on the remote server.

Thanks in advance.

Posted: Mon Nov 22, 2010 11:07 am
by kollurianu
narasimha wrote:Another way of doing this is to run sftp -b (Batch mode)
In the batch file you can write a get/mget followed by a rm
Thanks narsimha for your response , could you please elaborate how this can be done in an FTP enterprise stage as I am using an FTP enterprise stage to pull the files (SFTP) from remote server to local server.

any inputs , greatly appreciated.

Posted: Tue Nov 23, 2010 2:31 am
by ArndW
in pull mode you can't execute remote commands so you will have to "ssh" the delete command some other way in your job. Either as an after-job shell call or from the calling job sequence.

Posted: Tue Nov 23, 2010 7:12 am
by chulett
The stage has both telnet before and after options, from what I recall. They can be used for tasks such as this, although the fact that this is a secure connection may change that. :?

Posted: Tue Nov 23, 2010 8:29 am
by ArndW
I recall reading that sftp doesn't allow remote file actions such as delete, just local ones, so I don't think that this can be done, but it would certainly be worth a try - at worst there will be some error message and best case would be a solved problem!

Posted: Tue Nov 23, 2010 11:02 am
by kollurianu
ArndW wrote:in pull mode you can't execute remote commands so you will have to "ssh" the delete command some other way in your job. Either as an after-job shell call or from the calling job sequence.
Thanks for the response Arnd ! In my job sequencer , I've first job as SFTP job , which would pull the files from remote server to the local datastage server. After this how can I remove files from the remote server thru command stage , could you please explain me what command should be executed with syntax.

Any inputs greatly appreciated.Thank you all in advance.

Posted: Tue Nov 23, 2010 11:04 am
by ArndW
The command would be "rsh" or "ssh" and the exact syntax depends on your flavour of UNIX. Your userid must also be granted rsh or ssh priveleges on the remote machine so you will need to speak with your sysadm to ensure that permission is granted.

Posted: Tue Nov 23, 2010 11:42 am
by kollurianu
ArndW wrote:The command would be "rsh" or "ssh" and the exact syntax depends on your flavour of UNIX. Your userid must also be granted rsh or ssh priveleges on the remote machine so you will need to speak with your sysadm to ensure that permission is granted.
Thanks Arnd for a quick response. Datastage (local server) is on Linux and uses /bin/bash shell.

Could you please give me exact syntax to remove file on the remote server thru command stage in a sequencer.

And the id has permissions to delete files on the remote server , do we need any extra permissions to execute rsh/ssh on the remote server.

Any inputs greatly appreciated. Thanks in advance.

Posted: Wed Nov 24, 2010 4:52 am
by ArndW
try executing "rsh YourRemoteHostName ls -al" at the command line while logged into the system under the DataStage id. Does it work? If not, what is the error message?

Posted: Wed Nov 24, 2010 2:21 pm
by kollurianu
ArndW wrote:try executing "rsh YourRemoteHostName ls -al" at the command line while logged into the system under the DataStage id. Does it work? If not, what is the error message?
Thanks Arnd for your response.

I just tried with actual hostname .."rsh abc.def.com ls -al" and below is the error message.

-bash: rsh abc.def.com ls -al: command not found

And my unix id is not enabled to connect to the remote server without username and password only when I run thru datastage SFTP works without the user name and password.

so if you can give me the actual syntax for command activity stage . I shall try and run the sequencer.

Any inputs greatly appreciated.
Thanks in advance.

Posted: Thu Nov 25, 2010 2:12 am
by ArndW
You will need to talk with your UNIX administrator. It seems that either "rsh" is not installed or not in your path, likewise will most likely be the case for "ssh" as well. Once you sort out getting this command working (with or without adding userid/password) then you can implement it into DataStage.