Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Aditya

Winscp RemoteFileInfo how to convert the file into byte array in C# .net

Can you more elaborate like how you get the path and all using remote file info
martin

Re: Winscp RemoteFileInfo how to convert the file into byte array in C# .net

My response to your duplicate post on Stack Overflow:
https://stackoverflow.com/q/35312694/850848

WinSCP .NET assembly does not support "downloading" remote file contents to memory.

All you can do is to download the file to a local temporary location and read it to the memory from there.

using (Session session = new Session())

{
    // Connect
    session.Open(sessionOptions);
     
    // Download to a temporary folder
    string localPath = Path.GetTempFileName();
    session.GetFiles(remotePath, localPath).Check();
   
    // Read the file contents
    byte[] contents = File.ReadAllBytes(localPath);
   
    // Delete the temporary file
    File.Delete(localPath);
}
Aditya

Winscp RemoteFileInfo how to convert the file into byte array in C# .net

I am in trouble over on issue,I have to read a file content or read the file bytes and need to store in it our database.

How to do it in WinScp in .net System.Io.File we can simply call File.ReadAllBytes(file).

How to do it in Winscp RemoteFileInfo.

Sample code .

using (Session session = new Session())
{
session.Open(sessionOptions);
if (objFTP.RequestFor == "FR")
{
//sDirectoryPath.Append(objFTP.ReferenceNo);
directory = session.ListDirectory(basePath+objHCSAuthenticate.Source+"/"+objFTP.ReferenceNo); // Creation winscp Directory
}
else
{
//sDirectoryPath.Append(objFTP.PreAuthNo);
directory = session.ListDirectory(basePath + objHCSAuthenticate.Source + "/" + objFTP.PreAuthNo); // Creation winscp Directory
}



}
foreach(RemoteFileInfo fileInfo in directory.Files)
{

string sFileNAme = string.Empty;
string sDocShortCode = string.Empty;
string sDocType = string.Empty;

// sFileNAme = Path.GetFileName(file1);
sFileNAme = fileInfo.Name;
string[] FileNameArray = sFileNAme.ToString().Split('_');
sDocShortCode = FileNameArray[1]; //Get DocumentShortCode
sDocType = GetDocumentType(sDocShortCode);
//byte[] bytes = File.ReadAllBytes(file1);

byte[] bytes =System.Text.Encoding.UTF8.GetBytes(fileInfo.GetHashCode);
}