I want to automate the mounting of a sshfs connection inside my C program (meant for linux) using only password for ssh. (I don't want to use public/private keys.)
It seems i could do it with libexpect. Based on this thread it seems possible to use libexpect to give the password when required. For example, i made a successful test program that creates a dir with sudo mkdir test
and then provide the user password with libexpect. So that pipe seems really to be bidirectional. Thou, with sshfs and my simple function below, it doesn't work: i do have a sshfs mount produced by it, but it doesn't work and i can't see the files.
enum{ASKCONTINUE,ASKPWD};
int sshfs_connect (char data[10][200], char ip[]) {
char commandline[300];
sprintf(commandline,"sshfs %s@%s:%s %s -p %s -o ServerAliveInterval=15",
data[4],ip,data[6],data[5],data[7]);
bool shouldBreak = false;
FILE* fp = exp_popen(commandline);
while(shouldBreak == false)
{
switch(exp_fexpectl(fp,
//if asked for continuing (authenticity can't be established)
exp_glob, "ontinue connecting (yes/no)?", ASKCONTINUE,
//if asked for pwd
exp_glob, "s password:", ASKPWD,
exp_end)) //
{
case ASKCONTINUE:
printf("asked continue? !\n");
fprintf(fp,"%s\n","yes");
break;
case ASKPWD:
printf("asked pwd ! sending pwd: %s\n",data[8]);
fprintf(fp,"%s\n",data[8]);
shouldBreak = true;
break;
case EXP_TIMEOUT:
shouldBreak = true;
break;
case EXP_EOF:
shouldBreak = true;
break;
}
}
fclose(fp);
return 0;
}