Quantcast
Channel: SSH.NET Library
Viewing all articles
Browse latest Browse all 2955

New Post: Carriage Returns Stipped from Downloaded File?

$
0
0

Thank You for the quick reply Oleg!  Yes I am connecting to an SFTP server.

My simple test file contents looks like this when edited in Notepad:

record number one

record number two

record number three

When I download the file, and open in Notepad, it looks like this:

record number onerecord number tworecord number three

I believe that the \r\n's are being replaced with \r only.

Here is the code I am using:

Imports Renci.SshNetImports SystemImports System.CollectionsPublicEnum SFTP_ConnType
    Unknown
    User_Password
    PrivateKey_PassPhraseEndEnumPublicModule SshSftpPublicSub DownLoadDir(ByVal conType As SFTP_ConnType, _ByVal sHost AsString, _ByVal sUserID AsString, _ByVal sPrivateKeyPath AsString, _ByVal sPassPhraseOrPW AsString, _ByVal iPort AsInteger, _ByVal sDirLocal AsString, _ByVal sDirRemote AsString, _ByVal sFilter AsString, _ByRef files AsString(), _ByVal Overwrite AsBoolean, _ByVal RemoveFromServer AsBoolean)If (Not sDirLocal.EndsWith("\")) Then sDirLocal += "\"If (Not System.IO.Directory.Exists(sDirLocal)) Then System.IO.Directory.CreateDirectory(sDirLocal)Dim sDestFile AsString = String.EmptyDim bAdded AsBoolean = FalseDim fname AsString = String.EmptyDim dlist AsNew List(Of String)()Dim iResult As Int32 = 0If (sDirRemote.Length = 0) Then sDirRemote = "./"If (Not sDirRemote.EndsWith("/")) Then sDirRemote += "/"Dim conn As ConnectionInfo = NothingSelectCase conTypeCase SFTP_ConnType.PrivateKey_PassPhraseDim pk = New PrivateKeyFile(System.IO.File.OpenRead(sPrivateKeyPath), sPassPhraseOrPW)
                conn = New PrivateKeyConnectionInfo(sHost, iPort, sUserID, pk)Case SFTP_ConnType.User_Password
                conn = New PasswordConnectionInfo(sHost, iPort, sUserID, sPassPhraseOrPW)EndSelectDim sf = New SftpClient(conn)

        sf.Connect()
        Dim dirlist = sf.ListDirectory(sDirRemote)If (NotObject.ReferenceEquals(dirlist, Nothing)) ThenForEach f In dirlistIfNot f.IsDirectory Then
                    bAdded = False
                    fname = f.Name'if a file pattern is specified, we need to see if they matchIf (sFilter.Length = 0 Or sFilter = "*.*") Then
                        bAdded = TrueElseIf (fname.ToUpper() Like sFilter.ToUpper()) Then
                            bAdded = TrueEndIfEndIfIf (bAdded AndNot Overwrite) Then
                        bAdded = Not (System.IO.File.Exists(sDirLocal & fname))EndIfIf (bAdded) Then dlist.Add(fname)EndIfNextEndIf''Now go get each file we just foundForEach sfile In dlist
            fname = sDirRemote + sfile
            sDestFile = sDirLocal + sfileDim oOutput = New System.IO.FileStream(sDestFile, System.IO.FileMode.Create)
            sf.DownloadFile(fname, oOutput)
            oOutput.Close()
            oOutput.Dispose()Next
        sf.Disconnect()
        files = dlist.ToArray()EndSub

The version of CoreFTP that I use is CoreFTP LE v 2.2 build 1751.

The version of the Renci.SshNet.dll that I am using is the 3.5 build.

Thank you for taking the time to reply back to me, I appreciate it.

-Mike


Viewing all articles
Browse latest Browse all 2955

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>