Hi, I'm trying to send a file to an SFTP server. I can connect to the server without a problem, but when it comes to sending the file nothing happens. I suspect it may be the file path although I've tried every combination possible. Could it be a setting on the server itself? I've successfully transferred files using a different SFTP client. Here is my code...
public partial class Form1 : Form
{
private static String username = "";
private static String password = "";
private static String serverAddress = "";
private static int serverPort = 22;
private static String filename = "";
private static String sPath = "";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
filename = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
filename = openFileDialog1.FileName;
textBox_fileName.Text = filename;
}
}
private void button1_Click(object sender, EventArgs e)
{
Rebex.Net.Sftp client = new Rebex.Net.Sftp();
serverAddress = textBox_hostName.Text;
username = textBox_UserName.Text;
password = textBox_Password.Text;
serverPort = Int32.Parse(textBox_Port.Text);
sPath = textBox_serverPath.Text;
string sFileName = textBox_fileName.Text;
try
{
client.Connect(serverAddress, serverPort);
client.Login(username, password);
client.PutFile(sFileName, sPath);
}
catch (Exception exception)
{
Console.WriteLine(exception.GetBaseException().ToString());
}
}
}