I am having a problem with a simple sftp file transfer. I am starting to wonder if there is a problem when I change the port from standard 22 to a custom port of 5929. I can connect to the remote server using putty and Winscp using port 5929. My application will connect to my local Linux machine (CENTOS) using port 22 without a problem. However, when I try to use the application to connect to the remote server on port 5929 it times out and the log does not show that there was an attempt.
Any ideas?
Note: This is a test program, the idea is to use a configuration file for the data.
const int port = 5929;
Any ideas?
Note: This is a test program, the idea is to use a configuration file for the data.
const int port = 5929;
const string host = "****";
const string userName = "******";
const string password = "***";
const string workingdirectory = "/";
const string uploadfile = @"c:/Projects/test/HCCS.txt";
var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(userName);
keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs)
{
foreach (var prompt in eventArgs.Prompts)
{
if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase))
{
prompt.Response = password;
}
}
};
var passwordAuthMethod = new PasswordAuthenticationMethod(userName, password);
var connectInfo = new ConnectionInfo(host, userName, passwordAuthMethod, keyboardAuthMethod);
Console.WriteLine("Creating client and connecting");
Console.WriteLine(host);
using (SftpClient client = new SftpClient(connectInfo))
{
try
{
client.OperationTimeout = new TimeSpan(0, 0, 30);
client.Connect();
}
catch (Exception exe)
{
Console.WriteLine(exe.ToString());
}
if (client.IsConnected)
{
Console.WriteLine("Connected to {0}", host);
var ls = client.ListDirectory(".");
foreach (var s in ls)
{
Console.WriteLine(s);
}
}
else
Console.Write("Not Connected");
Console.Read();