Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: SFTPPermissionDeniedexception while uploading CSV file (rootfolder issue?)

$
0
0
we cannot upload file to SFTP server. Below is the code:
        SftpClient sftp = null;
        try
        {
            byte[] b = GetBytes(csvFile.CSVFileString);
            int port = 22;
            using (sftp = new SftpClient(ftpInfo.Url, port, ftpInfo.UserName, ftpInfo.Password))
            {
                sftp.Connect();                    
                MemoryStream stream = new MemoryStream(b);
                try
                {        
                    sftp.BufferSize = 4 * 1024;
                    sftp.UploadFile(stream, csvFile.CSVFileName);
                }
                catch (Exception ftpex)
                {
                    throw new Exception("SFTP failure : " + ftpex.Message);
                }                    
                sftp.Disconnect();
            }  
        }
If we add sftp.ChangeDirectory("/Data/test"); it uploads it successfully at "/data/test" folder on SFTP server. Cannot we upload at the root folder? or do we have to configure SFTP server to allow it?

Viewing all articles
Browse latest Browse all 1729

Trending Articles