This project is read-only.

sftp download file

Nov 1, 2014 at 7:30 AM
hi
i can't find sample code for downloading file

uploading file is very easy but i cant download file from server

Please attach a sample code

thanks
Nov 1, 2014 at 11:31 AM
this is my downloading file code

public void download()
    {

        if (connection_flag == false)
            connect();


        string downloadedFileName = "upload/01fe46c977e2cbf2159b571a2503a686.zip";
        using (var stream = new FileStream("E:\\abedi", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
        {

            //download the file to our local path
            sftp.DownloadFile(downloadedFileName, stream);
            stream.Close();

        }
    }
error doanloading is : Access to the path 'E:\abedi' is denied.
Nov 1, 2014 at 7:40 PM
using (var client = new SftpClient("<address>", <port>, <uid>, "<pw>"))
{
client.Connect();
List<Renci.SshNet.Sftp.SftpFile> Files = client.ListDirectory("<ftp file directory>").ToList();

foreach (Renci.SshNet.Sftp.SftpFile CurrentFile in Files)
{
  /// Download into file stream
       FileStream fs = new FileStream(Folder + CurrentFile.Name, FileMode.Create);
       client.DownloadFile(CurrentFile.Name, fs);

       /// Close file stream
       fs.Close();
}

client.Disconnect();
}


Hope this helps.
Coordinator
Nov 4, 2014 at 7:24 PM
@abedi98:
Is E:\abedi a directory ?
You should specifiy a file path as argument for the FileStream constructor.

Hope this helps,
Gert