tags:

views:

736

answers:

4

What would be the best way to do an scp or sftp copy in a unix environment using C. I'm interested in knowing the best library to use and an example if at all possible. I'm working on a solaris server with the sun tools installed.

+3  A: 

libssh2, perhaps? I have used the perl binding successfully to scp/sftp files, so I'm assuming it is not much harder to do the same with the core c API.

Mike Ellery
A: 

In the past I've simply called a shell script that contains the file transfer code.

int transferFile()
{
  //declare the transfer command
  char transferCommand[50] = "/home/tyler/transferFile.shl";
  //execute the command
  return system(transferCommand);
}

This will return 1 if the transfer command returns successfully.

Tyler Gooch
A: 

I'm not really a C expert, but I think you can use system() to run OS commands. This would assume that you don't actually want to re-implement scp, just use it.

mk
A: 

I've always just used the system() command. Of course doing this requires that you have ssh keys properly installed between the client and target machine so that it doesn't prompt for the password.

dagorym