Jump to content
  • Advertisement
Sign in to follow this  
corrington_j

transfering file over ssh from c++

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am wondering how i can transfer files over ssh to our server either using c++ or from a command prompt. Currently i just do it manually with winscp3, but i want to automate the copying of certain files from my computer to the server. Thanks for the help.

Share this post


Link to post
Share on other sites
Advertisement
The putty package has a commandline version of scp (pscp) that I usually use.
I don't know of any ssh libraries you could use but I suspect that you're better off invoking external programs programmatically anyway.
I recommend setting up a simple batch script to do the work, that's the kind of work they were designed to do. Automated password management might be painful though..

Share this post


Link to post
Share on other sites
To do this in the past, I've used perl with Expect. This works probably only on unix systems, and is a little hacked together.

sub scp{

my $experr;
my $find;
my $buf;
my $rtn="";
my $cli=shift;
my $from=shift;
my $to=shift;
my $pass=shift;

if (!($cli&$from&$to&$pass)){
return 0;
}
print $cli "scp -q -r $from $to\n";
($rtn,$experr,$find,$buf,undef)=$cli->expect(60,"password:","Are you sure you want to continue connecting (yes/no)?");
if (!$rtn){
return 0;
}
if ($rtn==2){
#Then the damned RSA key passing question is up
$cli->print ("yes\n");
($rtn,$experr,$find,$buf,undef)=$cli->expect(20,"password:");

if (!$rtn){
return 0;
}
}

$cli->print ("$pass\n");

($rtn,$experr,$find,$buf,undef)=$cli->expect(600, "-re","^.*[\#\>\$]");
return $rtn;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by corrington_j
so you mean to use a dos batch to call pscp and login and transfer the files. Or does pscp have its own form of a batch file.
No, just a regular .bat file. Or your scripting language of choice really..

Uploading a directory (project) should be as easy as this:
pscp -p -r -pw password project user@hostname:project
If that's all you need then simply throw it in a batch file and execute it whenever necessary..

Share this post


Link to post
Share on other sites
Quote:
Original post by corrington_j
okay, i figured out how to transfer file, now i need to execute some commands, do i do that with putty?
Try plink from the putty package. It's got a useful (-m) option for executing commands from a file.

Share this post


Link to post
Share on other sites
ok, i figured out how to transfer the files, and connect with plink, but i cannot figure out how to execute commands with plink to build my code. heres what i am trying. The last two lines are where i need help. Thanks.

set PATH="C:\Program Files\putty";%PATH%

pscp -p -r -pw pass "C:\*.cpp" "C:\*.h" "C:\make.txt" dbadmin@Vgdb:/home/code/

plink -batch -l dbadmin -pw pass dbadmin@Vgdb
plink cd /home/dbadmin/Code/ImageRecon
plink make -f make.txt

Share this post


Link to post
Share on other sites
Quote:
Original post by corrington_j
plink -batch -l dbadmin -pw pass dbadmin@Vgdb
plink cd /home/dbadmin/Code/ImageRecon
plink make -f make.txt
You can't repeatedly call plink and expect it to keep the connection, everything has do be done in a single invokation.
So either combine both commands with a ";" (plink expects to see them as the last thing on the line, after the connection parameters), or send them through a separate script file with the -m option.

Share this post


Link to post
Share on other sites
I tried this, but it won't connect now.

plink -batch -l dbadmin -pw pass dbadmin@Vgdb;
cd /home/dbadmin/Code/ImageRecon;
make -f make.txt

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!