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);  

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
ChrisPBacon
  • 177
  • 2
  • 15

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
  • 188,800
  • 56
  • 490
  • 992
  • 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