I am trying to save a sftp file in C#. I have found this example on SaveFileDialog but I cannot get it to work on my application (in fact, i get an error whenever I try to use SaveFileDialog saying it doesn’t exist and I cannot resolve the issue)
Is this the right way to save a file? I am not clicking a button, but getting an sftp file from another location, and saving it locally so I can execute some commands on it.
I am using Microsoft Visual Studio 2010 if that helps.
Edit: I think I confused people with the example that I found. Here is how I am getting the files:
protected void Page_Load(object sender, EventArgs e)
{
Sftp sftp = new AmexSFTP.src.Sftp(Config.sSFTPUrl,
Config.sSFTPAccount,
Config.sSFTPPasswd);
// Connect to SFTP server
sftp.Connect();
List<string> InputFiles = sftp.GetFileList("output");
//Save files in for each loop here...
....}
public Sftp(string sftpHost, string user, string password)
: base(sftpHost, user, password)
{
Init();
}
private void Init()
{
m_monitor = new MyProgressMonitor(this);
}
public List<string> GetFileList(string path)
{
List<string> list = new List<string>();
foreach (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry in SftpChannel.ls(path))
{
list.Add(entry.getFilename().ToString());
}
return list.ToList();
}
Maybe SaveFileDialog is not correct? It was what I found for all my google results, so I assumed it was.
Thanks!
I think you are confusing things a bit. Unless I am mistaken the Page_Load() method is part of an ASP.NET WebForms project. If that’s the case then you are mixing technologies: SaveFileDialog is a WinForms control which is normally used for client applications, not a web pages’s code-behind code.