Hi I have used the below lines of to post files.

Here is the line of code which I am using to retrieve the Server which the application is connecting to .

SFTPServerName = sftp.Session.ServerName;

but it is returning the SFTPURL but not the name of the server.

Kindly help me in resolving the issue.

public bool SFtpTheFile(string fileName, string sFtpServerurl, string sFtpDirectory, string userName, string password)

    {
        bool isSuccess = false;
        try

        {
            Sftp sftp = new Sftp();
            sftp.Connect(sFtpServerurl );
            sftp.Login(userName, password);
            sftp.PutFiles(fileName, sFtpDirectory, SftpBatchTransferOptions.Default, SftpActionOnExistingFiles.OverwriteAll);
            isSuccess = true;
            sftp.RemoteEndPoint.
            GetServerName = sftp.Session.ServerName;
            sftp.Disconnect();

        }
        catch(Exception ex)
        {
            isSuccess = false;
            ErrorMessage = ex.Message;
        }
        return isSuccess;
    }

asked 26 Jan, 14:25

keshav77's gravatar image

keshav77
15
accept rate: 0%


Hello

the ServerName is a property which contains the argument from the Connect() method.

If you are looking for translating with DNS, please try

using System.Net;    
IPHostEntry entry = Dns.GetHostEntry(serverName);
Console.WriteLine(entry.HostName);

Hope it helps,

with kind regards Tomas Knopp Rebex.NET

link

answered 26 Jan, 15:13

Tom%C3%A1%C5%A1%20Knopp's gravatar image

Tomáš Knopp ♦♦
15
accept rate: 0%

It doesn't worked for me still that is returning the same.

I will explain you my requirement.

SFTP is setup in SFTP Server Farm.

The client urls are provided to connect and post the files. In the SFTP Farm environment, If from a SFTP client is connecting and posting their files I have a requirement to find out which server it is connecting to. Hope the additional information will help me getting a resolution. Thanks in advance

(27 Jan, 10:03) keshav77

Thanks for your help. The commands are not recognized I get operation timed ou.We need the sever name for finding the issues when posting a file to sftp environment. I need to check the Server Enviroment

(29 Jan, 12:12) keshav77

The server environment is Windows Server 2008 R2 Standard SP1 64-bit

(30 Jan, 15:12) keshav77

It didn't work, because the SFTP server farm appears to the client as one server. With your SFTP client you connect to the farm and the rest is business of the farm. So even if you might be assigned to one of the servers that form the farm, the SFTP still returns the name of the whole farm, because it doesn't know anything else.

So the SFTP protocol itself cannot help you, but SFTP runs over SSH, which could do what you want.

One soulution that might work is to run command on the server you are connected to. (If the server allows it, of course.) You can use the SftpCommandRunner helper class.

A sample of use:

         Sftp client = new Sftp();
         client.Connect(…);
         client.Login(…);

         string hostname = SftpCommandRunner.RunCommand(client, "hostname -f");
         string ipaddress = SftpCommandRunner.RunCommand(client, "hostname -i");
         Console.WriteLine(hostname);
         Console.WriteLine(ipaddress);

However, the commands are definitely OS dependant. The example would work on servers with unix systems on it.

By the way, why do you want to do it at all?

link

answered 27 Jan, 14:50

Tom%C3%A1%C5%A1%20Knopp's gravatar image

Tomáš Knopp ♦♦
15
accept rate: 0%

Hello

ok try to use the command echo %COMPUTERNAME% or alternatively hostname.

link

answered 30 Jan, 17:10

Tom%C3%A1%C5%A1%20Knopp's gravatar image

Tomáš Knopp ♦♦
15
accept rate: 0%

Still No luck.I am getting timed out exception only.

(31 Jan, 10:54) keshav77

In that case, please try adding the following line to the RunCommand method (from SftpCommandRunner helper class) to produce a log that contains the communication between the client and the server:

        ...
        channel = sftp.Session.OpenSession();

// add the following line:
        sftp.Session.LogWriter = new Rebex.FileLogWriter(@"c:\temp\sshexeclog.txt", Rebex.LogLevel.Verbose);
        // (change the log path as needed)

channel.RequestExec(command);
        ...

Then, please mail the log to support@rebex.net for analysis. We should be able to tell what is going on!

(31 Jan, 13:13) Lukas Pokorny ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×116

Asked: 26 Jan, 14:25

Seen: 84 times

Last updated: 31 Jan, 13:13