CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    [RESOLVED] Ssh & sftp

    Hi,

    I was initialize SSH like below & its working
    Code:
    #include <iostream>
    #include <string>
    #include <WS2tcpip.h>
    #pragma comment(lib, "ws2_32.lib")
    using namespace std;
    
    WSAData data;                   // Initialize WinSock
    CString sipAddress;
    int port = 22;			// Listening port # on the server
    
    void CVSSHDlg::OnBnClickedConnect()
    {	
    	WORD ver = MAKEWORD(2, 2);
    	int wsResult = WSAStartup(ver, &data);
    	if (wsResult != 0)
    	{
    		cerr << "Can't start Winsock, Err #" << wsResult << endl;
    		TRACE("Can't start Winsock, Err #\n\n");
    		return;
    	}
    
    	// Create socket
    	SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
    	if (sock == INVALID_SOCKET)
    	{
    		cerr << "Can't create socket, Err #" << WSAGetLastError() << endl;
    		TRACE("Can't create socket, Err #\n\n");
    		WSACleanup();
    		return;
    	}
    
    	// Fill in a hint structure
    	sockaddr_in hint;
    	hint.sin_family = AF_INET;
    	hint.sin_port = htons(port);
    	cntlIPaddr.GetWindowTextA(sipAddress); //255.255.255.255
    	
    	inet_pton(AF_INET, sipAddress, &hint.sin_addr);
    	
    	CString str = "";
    	// Connect to server
    	connResult = connect(sock, (sockaddr*)&hint, sizeof(hint));
    	::AfxMessageBox(sipAddress);
    	if (connResult == SOCKET_ERROR)
    	{
    		cerr << "Can't connect to server, Err #" << WSAGetLastError() << endl;
    		TRACE("Can't connect to server, Err  #\n\n");
    
    		str.Format("Can't connect to server %s", sipAddress);
    		::AfxMessageBox(str);
    
    		closesocket(sock);
    		WSACleanup();
    		return;
    	}
    	else
    	{
    		str.Format("Connected with %s", sipAddress);
    		::AfxMessageBox(str);
    	}	
    }
    I like to send a file using SFTP.
    How is possible?
    Regards,

    SaraswathiSrinath

  2. #2
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    Re: Ssh & sftp

    Is libssh helps to copy a file via VC++?

    I want to copy a file from a client to a remote server but I don't understand how to do it with the library libssh and the function sftp in libssh.

    I did not find an easy way to copy a file from the client to the server.

    I like to transfer a file from source(windows) to destination(linux)?
    Source File Path - d:\test.txt
    Destination File Path - /root/
    Last edited by saraswathisrinath; June 10th, 2020 at 11:52 PM.
    Regards,

    SaraswathiSrinath

  3. #3
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    Re: Ssh & sftp

    finally done by libssh

    Thank you.
    Regards,

    SaraswathiSrinath

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured