Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: scp odd behavior

$
0
0
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.

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>