0

I'm getting error on sftp.GetFileList(ftpHost) with message "No such file". Using the given ip and credentials I've tested they have permissions to all the directories I'm connecting to.

    string FileName = Label6.Text;
    string rootPath = Server.MapPath("~");
    string FolderName = "\\DL" + DateTime.Now.ToString("yyyyMMddHHmmss");
    System.IO.Directory.CreateDirectory(rootPath + FolderName);
    string rootPath1 = rootPath + FolderName;
    string ftphost = "***.***.***.***";
    string ftpfullpath = "ftp://" + ftphost + FileName;
    int port = 22;


    Sftp sftp = new Sftp("***.***.***.***", "@!#^@!^$", "!@#^#@#^&");
    sftp.Connect(port);
    sftp.GetFileList(ftphost);
    ArrayList res = sftp.GetFileList(ftphost);
    foreach (var item in res)
    {
        if (item.ToString() != "." && item.ToString() != "..")
        Debug.WriteLine(item.ToString());

    }
    sftp.Get(ftpfullpath, rootPath1);  

Edit: Also the account used to connect to the ftp has a script on it that puts it into a specific directory, is it necessary to somehow redirect the Get or GetFileList to the root?

ChrisPBacon
  • 177
  • 2
  • 14

1 Answers1

2
  • The GetFileList method accepts a path to retrieve a listing for. Not hostname. You have specified the hostname in Sftp constructor already.
  • The same for Get method.
  • Moreover, you are using SFTP protocol, why the ftp:// prefix?
  • Note that you call GetFileList twice.
  • SharpSSH is a poor choice. It's not maintained for years.
Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
  • Thanks for pointing out the multiple getFileLists. Does the Get and GetFileList modify the path in any way or is (filename) acceptable? Is there an sftp:// prefix? Also is there a newer/better/free sftp library I can use? – ChrisPBacon Mar 09 '15 at 16:04
  • Not sure what you mean by "is (filename) acceptable". Use a path that you see when you login to the server using GUI SFTP client. Definitely no `sftp://` prefix. For recommendations, see [SFTP Libraries for .NET](http://stackoverflow.com/q/530330/850848). – Martin Prikryl Mar 09 '15 at 16:11
  • I appreciate your tips, I've got it working, also the ftp:// seems to work, why it does I don't know. – ChrisPBacon Mar 09 '15 at 16:32
  • You are welcome. Though on StackOverflow, we thank by accepting the answer! – Martin Prikryl Mar 09 '15 at 16:45
  • My apologies, still new (confused upvote with accepting) – ChrisPBacon Mar 09 '15 at 16:47