ChrisPBacon
ChrisPBacon

Reputation: 177

'No such file' using Tamir.SharpSSH to download file via sftp

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?

Upvotes: 0

Views: 1148

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202494

  • 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.

Upvotes: 2

Related Questions