I'm able to login to a server and execute scp commands using your library. I'm getting a weird behavior on upload. I need to upload a file to a folder off of the root called "in", but when I perform the upload command and setting the destination to "/in/testfile.txt" it gives me an "ambigous target" error. If I use "in/testfile.txt" it creates the file, but does so by creating a second in folder and putting the text file in there resulting in the file beingn in "/in/in/testfile.txt". Here is my code
public string putfile()
{
string status = "success";
string testfile = Server.MapPath("/App_Data/test2.txt");
string destfile = "in/" + Path.GetFileName(testfile);
try
{
var conn = connect3();
ScpClient m_scpclient = new ScpClient("192.168.0.0.1", 22, "username", new PrivateKeyFile(File.OpenRead(@"C:\keys\myprivatekey.ppk"), "keyphrase"));
//SftpClient m_sftpclient = new SftpClient(conn);
m_scpclient.Connect();
//m_sftpclient.Connect();
if (m_scpclient.IsConnected)
{
status = destfile;
m_scpclient.Upload(File.OpenRead(testfile), destfile);
//m_scpclient.Upload(File.OpenRead(testfile), @"\in\" + Path.GetFileName(testfile));
}
else
{
status = "disconnected";
}
}
catch (Exception ex)
{
status = ex.ToString() + destfile + testfile;
}
return status;
}
any help figuring this out would be greatly appreciated. I've tried several differentn combinations of backslashes, using "..\", "../". Everything gives the ambigous target error except the version that creates the duplicated directory. If I try it with just the file name it gives me an error because I don't have permissions to deposit files in the root.