use alternate port with SFTP

Max Barel max at ac-mb.info
Thu Mar 25 19:23:50 EDT 2010


Hi,
I eventually managed to patch the sftpdriver.c file in order to use the specified port of .sitecopyrc
Here are the diffs:

[max 00:14 sitecopy-0.16.6]$ diff src/sftpdriver.c*
87,89d86
< 	int port = sess->site->server.port;
< 	char buf_port[16];
< 	sprintf(buf_port, "-oPort=%d", (port != NULL ? port : 22));
99,101c96,98
<     execlp(sess->sftp_cmd, sess->sftp_cmd, buf_port, sess->buf, NULL);
<     NE_DEBUG(DEBUG_SFTP, "sftp exec: %s %s %s: %s\n",
<              sess->sftp_cmd, buf_port, sess->buf, strerror(errno));
---
>     execlp(sess->sftp_cmd, sess->sftp_cmd, sess->buf, NULL);
>     NE_DEBUG(DEBUG_SFTP, "sftp exec: %s %s: %s\n",
>              sess->sftp_cmd, sess->buf, strerror(errno));
146d142
< 	write(sess->fd_out, "\n", 1);

The last line diff is not related to the port option but was necessary or else the main process hang on reading the socket for the prompt.

I will not try to add it to the repository. I rather prefer that someone qualified will review the diffs and do it.

Anyhow it is now in this list for the next googler.


Max Barel



Le 15 mars 2010 à 19:31, Neil Cherry a écrit :

> On 03/10/2010 02:12 PM, Max Barel wrote:
>> Hi list,
>> While searching for the question in title, I found this old reply from Nobuyuki Tsuchimura:
>> 
>>> Try rcp "sftp -oPort=21" 
>>> in .sitecopyrc. "password" and "port" directives are ignored.
>> 
>> I tried it but it doesn't works maybe because it must not be used with "protocol sftp".
>> Can someone tell if it's possible at all to use sftp on alternate port (!=22)
>> 
> 
> Yes, it's possible but it will require a rewrite of the sftpdriver.c
> init() function such that you can pass the port number to sftp
> (change the line from sftp to sftp -o port %s for example).
> 
> -- 
> Linux Home Automation         Neil Cherry       ncherry at linuxha.com
> http://www.linuxha.com/                         Main site
> http://linuxha.blogspot.com/                    My HA Blog
> Author of:    	Linux Smart Homes For Dummies




More information about the sitecopy mailing list